1 导入#import <ImageIO/ImageIO.h>
2 获取图片根据图片大小进行切割
NSURL *gifImageUrl = [[NSBundle mainBundle] URLForResource:@"signChecking" withExtension:@"gif"];
//获取Gif图的原数据
CGImageSourceRef gifSource = CGImageSourceCreateWithURL((CFURLRef)gifImageUrl, NULL);
//获取Gif图有多少帧
size_t gifcount = CGImageSourceGetCount(gifSource);
NSMutableArray *imageS = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < gifcount; i++) {
//由数据源gifSource生成一张CGImageRef类型的图片
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(gifSource, i, NULL);
UIImage *image = [UIImage imageWithCGImage:imageRef];
[imageS addObject:image];
CGImageRelease(imageRef);
}
//得到图片数组
return imageS;
把数组图片通过imageView的动画添加 然后开始动画
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];//初始化
imageView.backgroundColor = [UIColor grayColor];//背景颜色
imageView.image = images.firstObject;
imageView.animationImages = images;
//动画的总时长(一组动画坐下来的时间 6张图片显示一遍的总时间)
imageView.animationDuration = 2;
imageView.animationRepeatCount = 0;//动画进行几次结束
[imageView startAnimating];//开始动画
// [imageView stopAnimating];//停止动画
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClick:)];
[imageView addGestureRecognizer:tap];
[self addSubview:imageView];