您的位置:首页 > 产品设计 > UI/UE

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: