SDWebImage4.x加载GIF图片的方法

saonian 发布于 02-15 08:20 459 点击
首先需要安装下面的两个包 ```bash pod 'SDWebImage/GIF' pod 'FLAnimatedImage' ``` 然后代码中引入这两个头文件 ```oc #import <FLAnimatedImageView.h> #import <FLAnimatedImageView+WebCache.h> ``` 加载gif图片需要使用FLAnimatedImageView ```oc // 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 评论

请登录后发表评论

saonian

all or nothing, now or never.

文章
回复
粉丝