animationImages

来源:互联网 发布:清木堂 知乎 编辑:程序博客网 时间:2024/05/07 22:27

http://blog.sina.com.cn/s/blog_bf9843bf0101fmwd.html

animationImages是数组类型,该数组必须包含的UIImage对象您可以使用相同的图像对象多次在阵中。
例如:

例如:将一系列帧添加到一个数组里面,然后设置animation一系列属性,如动画时间,动画重复次数,还是看代码吧,直观
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,代码如下
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]];
}


0 0
原创粉丝点击