自己先手动拖进工程一组图片,以.tiff为后缀的
//创建一个显示图片的imageview
UIImageView *showGIFImage = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:showGIFImage];
//创建一个存储图片的数组
NSMutableArray *saveArray = [NSMutableArray array];
for (int i = 1; i < 6; i++) {
NSString *imageName = [NSString stringWithFormat:@"%d.tiff",i];
UIImage *image = [UIImage imageNamed:imageName];
[saveArray addObject:image];
}
//设置GIF图片组
showGIFImage.animationImages = saveArray;
//设置播放速率
showGIFImage.animationDuration = 1.0f;
//设置播放次数(设置动图图重复的次数)[-1为无限次播放]
showGIFImage.animationRepeatCount = -1;
//动图需要设置开启
[showGIFImage startAnimating];
时间: 2024-10-29 19:07:53