首先需要安装下面的两个包
pod 'SDWebImage/GIF'
pod 'FLAnimatedImage'
然后代码中引入这两个头文件
#import <FLAnimatedImageView.h>
#import <FLAnimatedImageView+WebCache.h>
加载gif图片需要使用FLAnimatedImageView
// imageview
NSString *originalImagePath = [WEBSITE_PREFIX stringByAppendingPathComponent:self.imageItem[@"original"]];
UIImageView *imageView = [[UIImageView alloc] init];
if ([originalImagePath hasSuffix:@".gif"]) {
imageView = [[FLAnimatedImageView alloc] init];
}
self.imageView = imageView;
// SQDLog(@"%@", originalImagePath);
[imageView sd_setImageWithURL:[NSURL URLWithString:originalImagePath] completed:^(UIImage *_Nullable image, NSError *_Nullable error, SDImageCacheType cacheType, NSURL *_Nullable imageURL) {
if (!image) {
[SVProgressHUD showErrorWithStatus:@"图片下载失败"];
return;
}
self.saveBtn.enabled = YES;
}];