SDWebImage4.x加载GIF图片的方法

19-02-15 08:20 字数 680 阅读 3229

首先需要安装下面的两个包

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;
}];
0人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
190
收藏
31
排名 : 1
访问 : 127.9万
私信