标签:interface oar add alt layer let void 简单 mat
1.#import "ViewController.h"
2.
3.@interface ViewController ()
4.@property (weak, nonatomic) IBOutlet UIImageView *imageView;
5.
6./** 图片索引 */
7.@property (assign, nonatomic) NSInteger index;
8.@end
9.
10.@implementation ViewController
11.
12.- (void)viewDidLoad {
13. [super viewDidLoad];
14. self.imageView.image = [UIImage imageNamed:@"girl1"];
15.
16.}
17.
18.- (IBAction)next {
19. self.index++;
20. if (self.index == 9) {
21. self.index = 0;
22. }
23. NSString *imageName = [NSString stringWithFormat:@"girl%zd", self.index + 1];
24. self.imageView.image = [UIImage imageNamed:imageName];
25.
26. // 1. 创建动画
27. CATransition *anim = [CATransition animation];
28.
29.// anim.type = kCATransitionMoveIn;
30. anim.type = @"cube";
31.
32. anim.duration = 1.0;
33.
34. // 2. 添加动画
35. [self.imageView.layer addAnimation:anim forKey:nil];
36.}
37.
38.- (IBAction)forward {
39. self.index--;
40. if (self.index == -1) {
41. self.index = 8;
42. }
43. NSString *imageName = [NSString stringWithFormat:@"girl%zd", self.index + 1];
44. self.imageView.image = [UIImage imageNamed:imageName];
45.
46. // 1. 创建动画
47. CATransition *anim = [CATransition animation];
48.
49. // anim.type = kCATransitionMoveIn;
50. anim.type = @"cube";
51. anim.subtype = kCATransitionFromLeft;
52. anim.duration = 1.0;
53.
54. // 2. 添加动画
55. [self.imageView.layer addAnimation:anim forKey:nil];
56.}
57.@end
效果示例图:
标签:interface oar add alt layer let void 简单 mat
原文地址:http://www.cnblogs.com/leilifengixng/p/6367491.html