ios核心动画之专场动画

 1 #import "NJViewController.h"
 2 
 3 @interface NJViewController ()
 4 @property (weak, nonatomic) IBOutlet UIImageView *iconView;
 5 - (IBAction)nextBtnClick:(id)sender;
 6 - (IBAction)preBtnClick:(id)sender;
 7 
 8 @property (nonatomic, assign) int index;
 9 @end
10 
11 @implementation NJViewController
12 
13 // 下一张
14 - (IBAction)nextBtnClick:(id)sender {
15     self.index++;
16     if (self.index >7) {
17         self.index = 1;
18     }
19     
20     NSString *imageName = [NSString stringWithFormat:@"%d.jpg", self.index];
21     UIImage *newImage = [UIImage imageNamed:imageName];
22     self.iconView.image = newImage;
23     
24     // 1.创建核心动画
25     CATransition *ca = [CATransition animation];
26     // 1.1动画过渡类型
27     ca.type = @"cube";
28     // 1.2动画过渡方向
29     ca.subtype =  kCATransitionFromRight;
30     // 1.3动画起点(在整体动画的百分比)
31 //    ca.startProgress = 0.5;
32     ca.endProgress = 0.5;
33     
34     
35     // 动画时间
36     ca.duration = 1;
37     
38     // 2.添加核心动画
39     [self.iconView.layer addAnimation:ca forKey:nil];
40 }
41 
42 // 上一张
43 - (IBAction)preBtnClick:(id)sender {
44     self.index--;
45     if (self.index < 1) {
46         self.index = 7;
47     }
48     NSString *imageName = [NSString stringWithFormat:@"%d.jpg", self.index];
49     UIImage *newImage = [UIImage imageNamed:imageName];
50     self.iconView.image = newImage;
51     
52     // 1.创建核心动画
53     CATransition *ca = [CATransition animation];
54     // 1.1告诉系统执行什么动画
55     ca.type = @"cube";
56     ca.subtype =  kCATransitionFromLeft;
57     
58     ca.duration = 1;
59     
60     // 2.添加核心动画
61     [self.iconView.layer addAnimation:ca forKey:nil];
62 
63 }
64 @end

 

posted @ 2016-01-24 11:53  xiaocaoera  阅读(285)  评论(0编辑  收藏  举报