转场动画是针对view图层的动画ide
#import "DYViewController.h" @interface DYViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (nonatomic, assign) int index; @end @implementation DYViewController - (void)viewDidLoad { [super viewDidLoad]; _index = 1; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { _index++; if (_index == 10) { _index = 1; } NSString *fileName = [NSString stringWithFormat:@"%d",_index]; _imageView.image = [UIImage imageNamed:fileName]; CATransition *anim = [CATransition animation]; anim.type = @"pageCurl"; anim.subtype = kCATransitionFromLeft; anim.startProgress = 0.5; anim.duration = 2; [_imageView.layer addAnimation:anim forKey:nil]; }
视图控制器直接切换动画动画
只须要在window的layer上添加转场动画便可实现atom
@interface KKTestController () @end @implementation KKTestController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor redColor]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; btn.backgroundColor = [UIColor yellowColor ]; [btn addTarget:self action:@selector(testA:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } -(void)testA:(id)sender { KKTabBarController *test = [[KKTabBarController alloc] init]; CATransition *anim = [CATransition animation]; anim.type = @"oglFlip"; anim.subtype = kCATransitionFromRight; anim.duration = 2; UIWindow *window = [UIApplication sharedApplication].keyWindow; [window.layer addAnimation:anim forKey:nil]; window.rootViewController = test; }
属性解析: type:动画过渡类型 subtype:动画过渡方向 startProgress:动画起点(在总体动画的百分比) endProgress:动画终点(在总体动画的百分比)
/*type属性 过渡效果
fade //交叉淡化过渡(不支持过渡方向) kCATransitionFade
push //新视图把旧视图推出去 kCATransitionPushurl
moveIn //新视图移到旧视图上面 kCATransitionMoveIn
reveal //将旧视图移开,显示下面的新视图 kCATransitionReveal
cube //立方体翻滚效果
oglFlip //上下左右翻转效果
suckEffect //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl //向上翻页效果
pageUnCurl //向下翻页效果
cameraIrisHollowOpen //相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
*/
/*subtype 过渡方向spa
kCATransitionFromRight
kCATransitionFromLeft
kCATransitionFromBottom
code