手机
当前位置:查字典教程网 >编程开发 >IOS开发 >IOS UI学习教程之使用UIImageView控件制作动画
IOS UI学习教程之使用UIImageView控件制作动画
摘要:本文实例为大家分享了IOS使用UIImageView控件制作动画的方法,供大家参考,具体内容如下先添加40张tomcat的图片到资源列表中:...

本文实例为大家分享了IOS使用UIImageView控件制作动画的方法,供大家参考,具体内容如下

先添加40张tomcat的图片到资源列表中:名称为cat_eat0000.jpg到cat_eat0039.jpg。

1、定义所需控件

// 定义按钮,图片控件、可变数组对象 UIButton *actionbuttom; UIImageView *imageMove; NSMutableArray *imgsarray;

2、初始化各控件

// 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、设置按钮触发动画播放

//按钮的触发事件 -(void)startmove:(id)sender{ // 设置动画时长 imageMove.animationDuration = 2; // 设置动画图片来源为图片数组 imageMove.animationImages = imgsarray; // 设置动画重复次数,0是无限循环,1为重复1次 imageMove.animationRepeatCount = 1; // 开始播放 [imageMove startAnimating]; }

以上就是本文的全部内容,希望对大家学习使用UIImageView控件制作动画有所帮助。

【IOS UI学习教程之使用UIImageView控件制作动画】相关文章:

iOS 中使用tableView实现右滑显示选择功能

IOS使用UICollectionView实现无限轮播效果

iOS开发中使用Quartz2D绘制上下文栈和矩阵的方法

IOS轻松几步实现自定义转场动画

IOS自适配利器Masonry使用指南

iOS的UI开发中Modal的使用与主流应用UI结构介绍

iOS开发中使用Quartz2D绘图及自定义UIImageView控件

iOS应用开发中UITableView的分割线的一些设置技巧

详解iOS开发中UItableview控件的数据刷新功能的实现

iOS App中UITableView左滑出现删除按钮及其cell的重用

精品推荐
分类导航