核心动画

动画类型.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];
    
    
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容