本文实例为大家分享了IOS使用UIImageView控件制作动画的方法,供大家参考,具体内容如下
先添加40张tomcat的图片到资源列表中:名称为cat_eat0000.jpg到cat_eat0039.jpg。
1、定义所需控件
?
1
2
3
4
|
// 定义按钮,图片控件、可变数组对象
|
2、初始化各控件
?
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
|
// image动画
// 初始化UIImageView,大小和View的大小相同
imageMove = [[UIImageView alloc]initWithFrame:self.view.frame];
// 设置UIImageView的初始化图片
imageMove.image = [UIImage imageNamed:@ "cat_eat0000.jpg" ];
// 把UIImageView加载到页面
[self.view addSubview:imageMove];
// 设置UIImageView的交互性为yes
imageMove.userInteractionEnabled = YES;
// 创建功能按钮
// 初始化按钮
actionbuttom = [[UIButton alloc]initWithFrame:CGRectMake(100, 680, 218, 50)];
// 设置按钮背景色
actionbuttom.backgroundColor = [UIColor yellowColor];
// 设置按钮标题
[actionbuttom setTitle:@ "开始播放" forState:UIControlStateNormal];
// 设置按钮文字颜色
[actionbuttom setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// 为按钮添加触发事件
[actionbuttom addTarget:self action:@selector(startmove:) forControlEvents:UIControlEventTouchUpInside];
// 把按钮添加到页面中
[imageMove addSubview:actionbuttom];
// 初始化可变数组,用来存放图片
imgsarray = [[NSMutableArray alloc]initWithCapacity:40];
// 循环从资源中拿到四十张图片,并添加到imgsarray。
for ( int x=0; x<40; x++) {
NSString *imgname = [NSString stringWithFormat:@ "cat_eat00%.2d.jpg" ,x];
UIImage *img = [UIImage imageNamed:imgname];
[imgsarray addObject:img];
|
3、设置按钮触发动画播放
?
1
2
3
4
5
6
7
8
9
10
11
12
|
//按钮的触发事件
-( void )startmove:(id)sender{
// 设置动画时长
imageMove.animationDuration = 2;
// 设置动画图片来源为图片数组
imageMove.animationImages = imgsarray;
// 设置动画重复次数,0是无限循环,1为重复1次
imageMove.animationRepeatCount = 1;
// 开始播放
[imageMove startAnimating];
}
|
相关文章
猜你喜欢
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 49
-
2025-05-25 31
-
详解Spring Cloud Stream使用延迟消息实现定时任务(RabbitMQ)
2025-05-29 43 -
使用自助建站微信小程序时,怎样选择合适的模板以匹配品牌形象?
2025-06-04 78 -
2025-05-29 88
热门评论