CATransition继承自CAAnimation,他是在layer实现动画效果,它比UIView实现的动画类型要多,可以实现:交叉淡化过渡 、新视图移到旧视图上面 、新视图把旧视图推出去 、将旧视图移开,显示下面的新视图
需要在frameworks中添加QuartzCore.framework
在接口程序中加上头文件 #import <QuartzCore/QuartzCore.h>
1.#define定义的常量
kCATransitionFade 交叉淡化过渡
kCATransitionMoveIn 新视图移到旧视图上面
kCATransitionPush 新视图把旧视图推出去
kCATransitionReveal 将旧视图移开,显示下面的新视图
2.用字符串表示
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下翻转效果 将旧视图移开,显示下面的新视图
sample code:
<span style="font-size:18px;"> CATransition *animation=[CATransition animation];
animation.duration=0.6;
animation.timingFunction= [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromLeft;
[self.MyView.layer addAnimation:animation forKey:@"test" ];
[self.MyView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
</span>
用Transition实现pushViewController效果:
CATransition *animation = [CATransition animation];
animation.duration = 0.6;
animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:animation forKey:@"test"];
UIViewController *viewCtrl = [[UIViewController alloc] init];
[self.navigationController pushViewController:viewCtrl animated:NO];