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];