iOS开发笔记--UIImageView的属性之animationImages详解
2016-01-26 09:47
519 查看
animationImages是数组类型,该数组必须包含的UIImage对象。您可以使用相同的图像对象多次在阵中。
例如:将一系列帧添加到一个数组里面,然后设置animation一系列属性,如动画时间,动画重复次数,还是看代码吧,直观
[objc] view
plain copy
NSArray *magesArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.png"],
[UIImage imageNamed:@"image5.png"],nil];
UIImageView *animationImageView = [UIImageView alloc]init];
[animationImageView initWithFrame:CGRectMake(0, 0, 131, 125)];
animationImageView.animationImages = imagesArray;//将序列帧数组赋给UIImageView的animationImages属性
animationImageView.animationDuration = 0.25;//设置动画时间
animationImageView.animationRepeatCount = 0;//设置动画次数 0 表示无限
[animationImageView startAnimating];//开始播放动画
但是,如果图片少的话也许这种方式是最快速最容易达到目的的,但是图片很多的话,根据目前我做的实验,图片很多的话 这种方式程序必须会蹦,随后我会提到我们现在的实现方式,而且动画不能够实现暂停,只有停止,项目中要求序列帧播放的时候当手轻触(touch)播放暂停,松开后继续播放 ,横扫(swipe)播放加速,这一系列的需求表明了用animationImages这种方式实现已经不太现实.因为UIImageView的animation不会边用边释放(当然这点仅是我自己的拙见),那就导致了如果图片很多,animation直接崩掉根本
用不了,我们实现的原理就是用NSTimer去实现apple的UIImageView animation的效果,其实apple应该也是用NSTimer去实现吧(猜的),用NSTimer每隔一个时间戳去设置一次image,代码如下
[objc] view
plain copy
NSTimer *myAnimatedTimer = [NSTimer scheduledTimerWithTimeInterval:0.04 target:self selector:@selector(setNextImage) userInfo:nil repeats:YES];
-(void) setNextImage
{
myAnimatedView.image = [UIImage imageNamed:[NSStringstringWithFormat:@"image%i.png",nextImage]];
}
转自:http://blog.sina.com.cn/s/blog_bf9843bf0101fmwd.html
例如:将一系列帧添加到一个数组里面,然后设置animation一系列属性,如动画时间,动画重复次数,还是看代码吧,直观
[objc] view
plain copy
NSArray *magesArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.png"],
[UIImage imageNamed:@"image5.png"],nil];
UIImageView *animationImageView = [UIImageView alloc]init];
[animationImageView initWithFrame:CGRectMake(0, 0, 131, 125)];
animationImageView.animationImages = imagesArray;//将序列帧数组赋给UIImageView的animationImages属性
animationImageView.animationDuration = 0.25;//设置动画时间
animationImageView.animationRepeatCount = 0;//设置动画次数 0 表示无限
[animationImageView startAnimating];//开始播放动画
但是,如果图片少的话也许这种方式是最快速最容易达到目的的,但是图片很多的话,根据目前我做的实验,图片很多的话 这种方式程序必须会蹦,随后我会提到我们现在的实现方式,而且动画不能够实现暂停,只有停止,项目中要求序列帧播放的时候当手轻触(touch)播放暂停,松开后继续播放 ,横扫(swipe)播放加速,这一系列的需求表明了用animationImages这种方式实现已经不太现实.因为UIImageView的animation不会边用边释放(当然这点仅是我自己的拙见),那就导致了如果图片很多,animation直接崩掉根本
用不了,我们实现的原理就是用NSTimer去实现apple的UIImageView animation的效果,其实apple应该也是用NSTimer去实现吧(猜的),用NSTimer每隔一个时间戳去设置一次image,代码如下
[objc] view
plain copy
NSTimer *myAnimatedTimer = [NSTimer scheduledTimerWithTimeInterval:0.04 target:self selector:@selector(setNextImage) userInfo:nil repeats:YES];
-(void) setNextImage
{
myAnimatedView.image = [UIImage imageNamed:[NSStringstringWithFormat:@"image%i.png",nextImage]];
}
转自:http://blog.sina.com.cn/s/blog_bf9843bf0101fmwd.html
相关文章推荐
- 2016太原UI设计师郭文军图标的制作原则,面试必考
- iOS开发笔记--UILabel显示不同的字体和颜色
- iOS开发笔记--UIView中的坐标转换
- lightoj 1012 - Guilty Prince
- iOS应用UI开发中的字体和按钮控件使用指南
- IOS开发-UIView之动画效果的实现方法
- iOS UISearchController
- 《iOS Human Interface Guidelines》——Quick Look
- UIColor,CGColor,CIColor三者的区别和联系
- C#中SqlCommandBuilder批量数据增加修改
- 在 Windows 10 上安装 Arduino 开发环境
- Codeforces Round #328 (Div. 2) 592 B. The Monster and the Squirrel
- Priority Queue Implementation
- 4.9 Routing -- Query Parameters
- MiUI手机疯狂输出logcat处理
- 蜗牛爱课 -- iOS 设置UIButton的字体的大小、显示位置、大小
- Builder(建造者)模式
- 为啥UI设计师要学习产品思维?
- Request对象的主要方法
- [[UIScreen mainScreen] bounds]获取尺寸不对 解决