您的位置:首页 > 移动开发 > IOS开发

详解IOS图层转场动画

2016-02-14 15:33 791 查看

CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点
UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果
属性解析:

  • type:动画过渡类型
  • subtype:动画过渡方向
  • startProgress:动画起点(在整体动画的百分比)
  • endProgress:动画终点(在整体动画的百分比)

具体代码:

/* 过渡效果
fade   //交叉淡化过渡(不支持过渡方向) kCATransitionFade
push   //新视图把旧视图推出去 kCATransitionPush
moveIn  //新视图移到旧视图上面  kCATransitionMoveIn
reveal  //将旧视图移开,显示下面的新视图 kCATransitionReveal
cube   //立方体翻滚效果
oglFlip //上下左右翻转效果
suckEffect  //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl   //向上翻页效果
pageUnCurl  //向下翻页效果
cameraIrisHollowOpen //相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
*/
/* 过渡方向
kCATransitionFromRight
kCATransitionFromLeft
kCATransitionFromBottom
//转场动画--》是针对某个view的图层进行转场动画
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
{
UIView *_lastview;
BOOL flag;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
flag=true;
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
view.backgroundColor=[UIColor redColor];
[self.view addSubview:view];
[view release];
_lastview=view;
// Do any additional setup after loading the view, typically from a nib.
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(flag){
_lastview.backgroundColor=[UIColor yellowColor];
flag=false;
}
else{
_lastview.backgroundColor=[UIColor redColor];
flag=true;
}
//转场动画--就是对某个view进行动画切换。
//1:如果是控制器之间的切换,其实window上view进行切换
CATransition *transion=[CATransition animation];
//设置转场动画的类型
transion.type=@"pageCurl";
//设置转场动画的方向
transion.subtype=@"fromLeft";
//把动画添加到某个view的图层上
[self.view.layer addAnimation:transion forKey:nil];
}

 控制器直接切换动画

UIApplication *app=[UIApplication sharedApplication];
AppDelegate *dd=app.delegate;
MyViewController *my=[[MyViewController alloc] init];
//切换根控制器,其实把视图控制器的view在window上切换。所以在转场动画要作用在window上
dd.window.rootViewController=my;
CATransition *trans=[CATransition animation];
trans.type=@"pageCurl";
trans.subtype=@"fromTop";
[dd.window.layer addAnimation:trans forKey:nil];
[my release];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS 转场动画