目标
尝试NSTransition应用在NSBox setContentView:时的各种转场效果。下面是一个实例:
CATransition* transitionMoveIn = [CATransition animation];
transitionMoveIn.duration = 0.75f;
transitionMoveIn.type = kCATransitionMoveIn;
transitionMoveIn.subtype = kCATransitionFromLeft;
[self.contentBoxView.layer addAnimation:transitionMoveIn forKey:nil];
[self.contentBoxView setContentView:viewToSelect];
类型
我们可以通过设置type和subtype来尝试所有的转场效果。主要有:
- type为给定枚举常量
a. kCATransitionFade淡出
CATransition* transitionFade = [CATransition animation];
transitionFade.duration = 2;
transitionFade.type = kCATransitionFade;
transitionFade.subtype = kCATransitionFromLeft;
b. kCATransitionMoveIn覆盖原图
CATransition* transitionMoveIn = [CATransition animation];
transitionMoveIn.duration = 1;
transitionMoveIn.type = kCATransitionMoveIn;
transitionMoveIn.subtype = kCATransitionFromLeft;
c. kCATransitionPush推出
CATransition* transitionPush = [CATransition animation];
transitionPush.duration = 1;
transitionPush.type = kCATransitionPush;
transitionPush.subtype = kCATransitionFromLeft;
当然也可以设置从右边出来。transitionPush.subtype = kCATransitionFromRight; d. kCATransitionReveal底部显出
CATransition* transitionReveal = [CATransition animation];
transitionReveal.duration = 2;
transitionReveal.type = kCATransitionReveal;
transitionReveal.subtype = kCATransitionFromLeft;
让我们看看从底部出来的效果。transitionReveal.subtype = kCATransitionFromBottom; 2. type为字符串量。如setType [animation setType:@“suckEffect”],这里的suckEffect就是效果名称。 e pageCurl 向上翻一页
CATransition* transitionPageCurl = [CATransition animation];
transitionPageCurl.duration = 2;
transitionPageCurl.type = @"pageCurl";
transitionPageCurl.subtype = kCATransitionFromLeft;
从右边出来的效果如下: f. pageUnCurl 向下翻一页
CATransition* transitionPageUnCurl = [CATransition animation];
transitionPageUnCurl.duration = 2;
transitionPageUnCurl.type = @"pageUnCurl";
transitionPageUnCurl.subtype = kCATransitionFromLeft;
g. rippleEffect 滴水效果
CATransition* transitionRippleEffect = [CATransition animation];
transitionRippleEffect.duration = 2;
transitionRippleEffect.type = @"rippleEffect";
transitionRippleEffect.subtype = kCATransitionFromLeft;
h. suckEffect 收缩效果,如一块布被抽走
CATransition* transitionSuckEffect = [CATransition animation];
transitionSuckEffect.duration = 2;
transitionSuckEffect.type = @"suckEffect";
transitionSuckEffect.subtype = kCATransitionFromLeft;
i. cube 立方体效果
CATransition* transitionCube = [CATransition animation];
transitionCube.duration = 2;
transitionCube.type = @"cube";
transitionCube.subtype = kCATransitionFromLeft;
j. oglFlip 上下翻转效果
CATransition* transitionOglFlip = [CATransition animation];
transitionOglFlip.duration = 2;
transitionOglFlip.type = @"oglFlip";
transitionOglFlip.subtype = kCATransitionFromLeft;
参考
Iphone翻页动画效果–CATransition实现
|