#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; //UIImageView 负责显示图片的类 UIImageView* imageV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)]; imageV.backgroundColor=[UIColor yellowColor]; [self.view addSubview:imageV]; //创建一个图片 UIImage *ima=[UIImage imageNamed:@"a.jpg"]; //显示 imageV.image=ima; //逐帧动画 //设置要播放的资源 (这些资源是图片 并且这些图片放到数组中) NSMutableArray* array=[NSMutableArray array]; for(int i=0;i<=80;i++){ //创建80张图片并添加到一个数组中 drink_%d.jpg 指文件路径下 NSString* name=[NSString stringWithFormat:@"a.jpg"]; UIImage *image=[UIImage imageNamed:name]; [array addObject:image]; } NSLog(@"%@",array); imageV.animationImages=array; //设置动画时间 imageV.animationDuration=3; //设置重复次数 imageV.animationRepeatCount=2; //启动动画 [imageV startAnimating]; } @end
原文:https://www.cnblogs.com/zhangqing979797/p/13342118.html