首页 > 代码库 > CATransition自定义UIViewController过渡动画
CATransition自定义UIViewController过渡动画
CATransition
CATransition是CAAnimation的子类,可以通过设置type和subtype实现简单的过渡动画。
type类型:
/* Common transition types. */ CA_EXTERN NSString * const kCATransitionFade __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0); CA_EXTERN NSString * const kCATransitionMoveIn __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0); CA_EXTERN NSString * const kCATransitionPush __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0); CA_EXTERN NSString * const kCATransitionReveal __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
也可以直接用@“fade”,@"moveIn",@"push",@"reveal"代替,除了这四种还有:@“pageCurl”,@"cube",@"flip"等等。
subtype类型:
/* Common transition subtypes. */ CA_EXTERN NSString * const kCATransitionFromRight __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0); CA_EXTERN NSString * const kCATransitionFromLeft __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0); CA_EXTERN NSString * const kCATransitionFromTop __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0); CA_EXTERN NSString * const kCATransitionFromBottom __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
也可以直接使用对应的字符串:@”fromRight“,@"fromLeft",@"fromTop",@"fromBottom"
Present类型过渡动画
设置animated为NO,并将动画添加在self.view.window.layer上
/*** CATransition ***/ //CATransition - (CATransition *)transition { CATransition *transition = [CATransition animation]; transition.duration = 1; transition.type = @"cube"; transition.subtype = @"fromRight"; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; return transition; } - (void)onClick:(id)sender { ViewController2 *vc2 = [[ViewController2 alloc] init]; [self presentViewController:vc2 animated:NO completion:nil]; [self.view.window.layer addAnimation:[self transition] forKey:@"kTransitionAnimation"]; }
Push类型过渡动画
设置animated为NO,并将动画添加在self.view.window.layer或者self.navigationController.view.layer上
/*** CATransition ***/ //CATransition - (CATransition *)transition { CATransition *transition = [CATransition animation]; transition.duration = 1; transition.type = @"cube"; transition.subtype = @"fromRight"; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; return transition; } - (void)onClick:(id)sender { ViewController2 *vc2 = [[ViewController2 alloc] init]; [self.navigationController pushViewController:vc2 animated:NO]; [self.view.window.layer addAnimation:[self transition] forKey:@"kTransitionAnimation"]; // or [self.navigationController.view.layer addAnimation:[self transition] forKey:kTransitionAnimation]; }
CATransition自定义UIViewController过渡动画
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。