標籤:
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 @end10 11 @implementation NJViewController12 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
ios核心動畫之專場動畫