【iOS系列】-UIImageView帧动画相关属性介绍

UIImageView帧动画相关属性介绍

1:相关属性:

//An array of UIImage objects to use for an animation.存放UIImage对象,会按顺序显示里面的图片
@property(nonatomic,copy) NSArray *animationImages; 
	
//帧动画的持续时间
@property(nonatomic) NSTimeInterval animationDuration;
	
//帧动画的执行次数(默认是无限循环)
@property(nonatomic) NSInteger animationRepeatCount; 

//开始执行帧动画
- (void)startAnimating;

//停止执行帧动画
- (void)stopAnimating;

//是否正在执行帧动画
- (BOOL)isAnimating;

2:关于缓存

由于UIImageview是一下子把全部图片全部加载,所以当对于缓存一定要进行管理否则,程序性能是个大问题

2.1:我们从UIImage入手,image加载有两种方式,api中相关介绍如下

//This method does not cache the image object.
[UIImage imageWithContentsOfFile:name]

//This method looks in the system caches for an image object with the specified name and returns that object if it exists.
[UIImage imageNamed:name]

一般我们用的就是imageNamed,imageNamed中加载图片后有缓存,下次加载的时候,缓存中有就直接区,这对于我们平时使用很是便利,但是播放动画的时候,动辄几十张甚至几百张图片来说,我们就选择imageWithContentsOfFile这种方式

2.2:动画播放完毕后,要手动清理内存

CGFloat delay = self.tom.animationDuration + 1.0;
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];
原文地址:https://www.cnblogs.com/fengtengfei/p/4417140.html