@property (strong, nonatomic) IBOutlet UIImageView *tomImageView;
//创建图片数组
NSMutableArray *tomImages = [NSMutableArray array];
//图片的路径
NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg",fileName,i];
//这种方法有内存溢出,一般不使用
// UIImage *image = [UIImage imageNamed:imageName];
//这种方法不会内存溢出
NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[tomImages addObject:image];
//添加动画执行的数组
[self.tomImageView setAnimationImages:tomImages];
//添加动画执行的时间
[self.tomImageView setAnimationDuration:self.tomImageView.animationImages.count*0.1];
//添加动画执行的次数
[self.tomImageView setAnimationRepeatCount:1];
//开始动画
[self.tomImageView startAnimating];
//方法一,清空数组
// [self.tomImageView performSelector:@selector(clearImage) withObject:nil afterDelay:self.tomImageView.animationDuration];
//方法二,重新设置setAnimationImages
[self.tomImageView performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tomImageView.animationDuration];
- (void)clearImage {
self.tomImageView.animationImages = nil;
}
原文地址:http://blog.csdn.net/u011550635/article/details/42461071