1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #import "ViewController.h"
@interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (assign,nonatomic) int index; @end
@implementation ViewController
- (void)viewDidLoad { [super viewDidLoad]; _index=1; } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { _index++; if (_index==4) { _index=1; } NSString *fileName=[NSString stringWithFormat:@"%d",_index]; _imageView.image=[UIImage imageNamed:fileName]; CATransition *anim=[CATransition animation]; anim.type=@"cube"; [_imageView.layer addAnimation:anim forKey:nil]; } @end
|