我是靠谱客的博主 爱笑万宝路,这篇文章主要介绍IOS 开发之UIView动画的实例详解,现在分享给大家,希望可以做个参考。

IOS 动画实例详解

iOS动画的实现方式多种多样,这里就只记录一下 beginAnimations:context 。

在你调用 beginAnimations:context:方法来启动一个动画后,动画并不会立即被执行,直 到你调用 UIView 类的 commitAnimations 类方法。你对一个视图对象执行的介于 beginAnimations:context:方法跟 commitAnimations方法之间的操作(例如移动)会在 commitAnimations 被执行后才会生效 。

实现效果图:

代码很简单,直接贴了,如下:

复制代码
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// // ViewController.m // Graphics // // Created by aaron on 14b-5-29. // Copyright (c) 2014年 The Technology Studio. All rights reserved. // #import "ViewController.h" @interface ViewController () @property(nonatomic,strong) UIImageView *imageView1; @property(nonatomic,strong) UIImageView *imageView2; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"1.png"]; self.imageView1 = [[UIImageView alloc] initWithImage:image]; self.imageView2 = [[UIImageView alloc] initWithImage:image]; [self.imageView1 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [self.imageView2 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; [self.view addSubview:self.imageView1]; [self.view addSubview:self.imageView2]; // [self startTopLeftImageViewAnimation]; // [self startBottomRightViewAnimationAfterDelay:2]; [self affineTransformScaleAnimation]; [self affineTransformRotateAnimation]; } //imageView2 animation -(void)startTopLeftImageViewAnimation{ [self.imageView1 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [self.imageView1 setAlpha:1.0f]; [UIView beginAnimations:@"imageView1Animation" context:(__bridge void*)self.imageView1]; [UIView setAnimationDuration:3.0f]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)]; [self.imageView1 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; [self.imageView1 setAlpha:0.0f]; [UIView commitAnimations]; } -(void)imageViewDidStop:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{ NSLog(@"AnimationID = %@n",paramAnimationID); UIImageView *contextImageView = (__bridge UIImageView *)(paramContext); NSLog(@"contextImageView = %@",contextImageView); [contextImageView removeFromSuperview]; } //imageView2 animation -(void)startBottomRightViewAnimationAfterDelay:(CGFloat)paramDelay{ [self.imageView2 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; [self.imageView2 setAlpha:1.0f]; [UIView beginAnimations:@"imageView2Animation" context:(__bridge voidvoid *)(self.imageView2)]; [UIView setAnimationDuration:3.0f]; [UIView setAnimationDelay:paramDelay]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)]; [self.imageView2 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; [self.imageView2 setAlpha:0.0f]; [UIView commitAnimations]; } //imageView1 AffineTransformScale animation -(void)affineTransformScaleAnimation{ self.imageView1.center = self.view.center; self.imageView1.transform = CGAffineTransformIdentity; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:5.0f]; self.imageView1.transform = CGAffineTransformMakeScale(2.0f, 2.0f); [self.imageView1 setAlpha:0.0f]; [UIView commitAnimations]; } //imageView2 AffineTransformRotate animation -(void)affineTransformRotateAnimation{ self.imageView2.center = self.view.center; [UIView beginAnimations:@"clockwiseAnimation" context:NULL]; [UIView setAnimationDuration:5.0f]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(clockwiseRotationStopped:finished:context:)]; self.imageView2.transform = CGAffineTransformMakeRotation(90.0f*M_PI/180.f); [UIView commitAnimations]; } -(void)clockwiseRotationStopped:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{ [UIView beginAnimations:@"counterclockwiseAnimation" context:NULL]; [UIView setAnimationDuration:5.0f]; self.imageView2.transform = CGAffineTransformIdentity; [UIView commitAnimations]; } @end

以上就是关于IOS动画开发的实例,本站对于IOS 开发还有很多教程,大家可以搜索查阅!

最后

以上就是爱笑万宝路最近收集整理的关于IOS 开发之UIView动画的实例详解的全部内容,更多相关IOS内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部