#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *zhaoyunImage;
@end
--------------------------------------------------------------------------------------
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setDonghua:11 andButton:_zhaoyunImage];
}
- (void)setDonghua:(NSInteger)count andButton:(UIImageView *)imageView
{
NSMutableArray *imagesList = [NSMutableArray array];
for (NSInteger i = 1; i < count; i++) {
// 生成图像文件名
NSString *fileName = [NSString stringWithFormat:@"%d.png", i];
UIImage *image = [UIImage imageNamed:fileName];
// 把图像添加到数组
[imagesList addObject:image];
}
[imageView setAnimationImages:imagesList];
// 2.2 设置动画播放的时长
[imageView setAnimationDuration:1.0];
// 2.4 设置动画播放次数
[imageView setAnimationRepeatCount:1];
// 2.3 开始动画
[imageView startAnimating];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end