码迷,mamicode.com
首页 > 其他好文 > 详细

CATransition自定义UIViewController过渡动画

时间:2014-12-31 18:33:10      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

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过渡动画

标签:

原文地址:http://blog.csdn.net/nextstudio/article/details/42296559

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!