核心動畫

動畫類型.png
#import "ViewController.h"

@interface ViewController ()
{

  NSMutableArray *images;
  int index;
  
}

@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  index = 0;
  
  images = [NSMutableArray arrayWithCapacity:6];
  
  for (int i =0; i<6; i++) {
    
    NSString *string = [NSString stringWithFormat:@"%d.jpg",i+1];
    UIImage *iamge = [UIImage imageNamed:string];
    
    [images addObject:iamge];
    
  }
  
  
  self.imageView.image = [UIImage imageNamed:@"1.jpg"];
  self.imageView.userInteractionEnabled = YES;//用戶交互
  
  
  UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changeImage)];
  swipe.direction = UISwipeGestureRecognizerDirectionLeft;
  
  [self.imageView addGestureRecognizer:swipe];
  
  
  
  
  
}

-(void)changeImage{
  index++;
  
  if (index>=6) {
    index =0;
    
  }
  
  self.imageView.image = [images objectAtIndex:index];
    
    //轉場動畫
    CATransition *trans = [[CATransition alloc]init];
    
    //屬性
    //fade, `moveIn', `push' and `reveal
    trans.type = @"push";//動畫類型
    
    trans.duration = 1;
    
    //動畫過渡方向
    //fromLeft', `fromRight', `fromTop' and  fromBottom
    trans.subtype =@"fromLeft";
    
    
    
    [self.imageView.layer addAnimation:trans forKey:nil];
    
    
}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容