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