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

core Animation之CATransition(转场动画)

时间:2015-04-13 18:09:14      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点

UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果

属性解析:

type:动画过渡类型

subtype:动画过渡方向

startProgress:动画起点(在整体动画的百分比)

endProgress:动画终点(在整体动画的百分比)

代码一:

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)UIImageView *imgView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)];
    [self.view addSubview:self.imgView];
    UIButton *btn1=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:@"上一张" forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag=1;
    btn1.backgroundColor=[UIColor redColor];
    btn1.frame=CGRectMake(50, 100, 80,40);
    
    [self.view addSubview:btn1];
    
    UIButton *btn2=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setTitle:@"下一张" forState:UIControlStateNormal];
    btn2.tag=2;
    [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn2.frame=CGRectMake(150, 100, 80,40);
    btn2.backgroundColor=[UIColor redColor];
    [self.view addSubview:btn2];

    
}
-(void)btnClick:(id)sender
{
    UIButton *btn=(UIButton *)sender;
    if (btn.tag==1) {
        self.imgView.image=[UIImage imageNamed:@"1.jpg"];
        CATransition *transition=[CATransition animation];
        //动画效果
        transition.type=@"push";
        //动画方向
        transition.subtype=kCATransitionFromRight;
        transition.duration=2.0;
        [self.imgView.layer addAnimation:transition forKey:nil];
    }
    else
    {
        self.imgView.image=[UIImage imageNamed:@"2.jpg"];
        CATransition *transition=[CATransition animation];
        transition.type=kCATransitionMoveIn;
        transition.subtype=kCATransitionFromBottom;
        transition.duration=2.0;
        [self.imgView.layer addAnimation:transition forKey:nil];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 代码二:

技术分享

技术分享

技术分享

技术分享

core Animation之CATransition(转场动画)

标签:

原文地址:http://www.cnblogs.com/cuiyw/p/4422536.html

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