工作中我们拿到的是一个GIF文件,如果不作处理,直接使用SDWebImage就会无限次播放,那么我们只要他播放一次怎么办呢,上代码:
- (void)showGifImageOnlyOnceWithImageView:(UIImageView*)imageView path:(NSString*)path{
NSData *data = [NSData dataWithContentsOfFile:path];
CGImageSourceRef gifSource = CGImageSourceCreateWithData(CFBridgingRetain(data), nil);
size_tgifCount =CGImageSourceGetCount(gifSource);
NSMutableArray *frames = [[NSMutableArray alloc]init];
for(size_ti =0; i< gifCount; i++) {
CGImageRefimageRef =CGImageSourceCreateImageAtIndex(gifSource, i,NULL);
UIImage*image = [UIImageimageWithCGImage:imageRef];
[framesaddObject:image];
CGImageRelease(imageRef);
}
//从这里开始是不是很熟悉
imageView.animationImages= frames;
imageView.animationDuration=2;
imageView.animationRepeatCount = 1;
[imageViewstartAnimating];
}