1 #import "ViewController.h"
2
3 @interface ViewController ()
4
5 @end
6
7 @implementation ViewController
8
9 - (void)viewDidLoad {
10 [super viewDidLoad];
11
12 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
13 btn.frame = CGRectMake(20, 40, 80, 80);
14 [btn setTitle:@"动画一" forState:UIControlStateNormal];
15 [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
16 [btn addTarget:self action:@selector(animations1) forControlEvents:UIControlEventTouchUpInside];
17 [self.view addSubview:btn];
18
19 UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
20 btn1.frame = CGRectMake(110, 40, 80, 80);
21 [btn1 setTitle:@"动画二" forState:UIControlStateNormal];
22 [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
23 [btn1 addTarget:self action:@selector(animations2) forControlEvents:UIControlEventTouchUpInside];
24 [self.view addSubview:btn1];
25
26
27 UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
28 btn2.frame = CGRectMake(200, 40, 80, 80);
29 [btn2 setTitle:@"动画三" forState:UIControlStateNormal];
30 [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
31 [btn2 addTarget:self action:@selector(animations3) forControlEvents:UIControlEventTouchUpInside];
32 [self.view addSubview:btn2];
33
34 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(375/2.0-50, 300, 100, 100)];
35 view.backgroundColor = [UIColor brownColor];
36 view.tag = 1;
37 [self.view addSubview:view];
38
39 }
40
41 -(void)animations1{
42
43 UIView *view = [self.view viewWithTag:1];
44
45 [UIView beginAnimations:@"123" context:nil];//创建动画
46 [UIView setAnimationCurve:UIViewAnimationCurveLinear];//动画曲线(路径)
47 [UIView setAnimationDuration:2];//动画持续时间
48 [UIView setAnimationRepeatCount:1];//动画循环次数
49 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:YES];//设置动画效果,以及要执行动画的view
50
51 [UIView setAnimationDelegate:self];//设置动画的代理
52
53 [UIView setAnimationDidStopSelector:@selector(animationStop)];//动画结束后调用的方法,注意设置此方法之前要先设置代理
54
55 [UIView commitAnimations];//提交动画
56 }
57
58 -(void)animations2{
59
60 UIView *view = [self.view viewWithTag:1];
61
62
63 CATransition *animation = [CATransition animation];//创建动画
64 animation.duration = 2;//动画持续时间
65 // animation.repeatCount = 2;//动画循环次数
66 animation.type = @"cameraIrisHollowOpen";//设置动画类型
67 animation.subtype = kCATransitionFromLeft;//设置动画方向
68 animation.delegate = self;//设置动画代理
69 [view.layer addAnimation:animation forKey:@"1234"];//添加动画
70 }
71
72 -(void)animations3{
73
74 UIView *view = [self.view viewWithTag:1];
75
76 CGPoint center = view.center;
77
78 // [UIView animateWithDuration:1 animations:^{
79 // view.frame = CGRectMake(10, 10, 300, 300);
80 // view.center = center;
81 // }];
82
83 [UIView animateWithDuration:1 animations:^{
84 view.frame = CGRectMake(10, 10, 300, 300);
85 view.center = center;
86 } completion:^(BOOL finished) {
87 [UIView animateWithDuration:1 animations:^{
88 view.frame = CGRectMake(375/2.0, 300, 100, 100);
89 view.center = center;
90 }completion:^(BOOL finished) {
91 [self animations3];
92 }];
93 }];
94
95 // [UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:(UIViewAnimationOptions) animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]
96 }
97
98 -(void)animationDidStart:(CAAnimation *)anim{
99 NSLog(@"开始");
100 }
101
102 -(void)animationStop{
103 NSLog(@"动画停止");
104 }
105
106 - (void)didReceiveMemoryWarning {
107 [super didReceiveMemoryWarning];
108 // Dispose of any resources that can be recreated.
109 }
110 @end
1 #import "ViewController.h"
2
3 @interface ViewController ()
4
5 @end
6
7 @implementation ViewController
8
9 - (void)viewDidLoad {
10 [super viewDidLoad];
11
12 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
13 btn.frame = CGRectMake(20, 40, 80, 80);
14 [btn setTitle:@"动画一" forState:UIControlStateNormal];
15 [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
16 [btn addTarget:self action:@selector(animations1) forControlEvents:UIControlEventTouchUpInside];
17 [self.view addSubview:btn];
18
19 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 300, 100, 100)];
20 view.backgroundColor = [UIColor brownColor];
21 view.tag = 1;
22 [self.view addSubview:view];
23
24 }
25
26 -(void)animations1{
27
28 UIView *view = [self.view viewWithTag:1];
29
30 [UIView beginAnimations:@"123" context:nil];//创建动画
31 [UIView setAnimationCurve:UIViewAnimationCurveLinear];//动画曲线(路径)
32 [UIView setAnimationDuration:2];//动画持续时间
33 [UIView setAnimationRepeatCount:1];//动画循环次数
34 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:YES];//设置动画效果,以及要执行动画的view
35
36 [UIView setAnimationDelegate:self];//设置动画的代理
37
38 [UIView setAnimationDidStopSelector:@selector(animationStop)];//动画结束后调用的方法,注意设置此方法之前要先设置代理
39
40 [UIView commitAnimations];//提交动画
41 }
42
43 -(void)animationStop{
44 NSLog(@"动画停止");
45 }
46
47 - (void)didReceiveMemoryWarning {
48 [super didReceiveMemoryWarning];
49 // Dispose of any resources that can be recreated.
50 }
51
52
53
54
55 @end
transition.type 的类型可以有
淡化、推挤、揭开、覆盖
NSString * const kCATransitionFade;
NSString * const kCATransitionMoveIn;
NSString * const kCATransitionPush;
NSString * const kCATransitionReveal;
这四种,
transition.subtype
也有四种
NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
NSString * const kCATransitionFromBottom;
私有的类型的动画类型:
animation.type = @”cube”
animation.type = @”suckEffect”
animation.type = @”oglFlip”//没有方向
animation.type = @”rippleEffect”
animation.type = @”pageCurl”
animation.type = @”pageUnCurl”
animation.type = @”cameraIrisHollowOpen”
animation.type = @”cameraIrisHollowClose”