SDWebImage 4.0 GIF图片的使用

SDWebImage 官方说明

Animated Images (GIF) support

Starting with the 4.0 version, we rely on FLAnimatedImage to take care of our animated images.
If you use cocoapods, add pod 'SDWebImage/GIF'
to your podfile.
To use it, simply make sure you use FLAnimatedImageView
instead of UIImageView
.
Note: there is a backwards compatible feature, so if you are still trying to load a GIF into a UIImageView
, it will only show the 1st frame as a static image.
Important: FLAnimatedImage only works on the iOS platform, so for all the other platforms (OS X, tvOS, watchOS) we will fallback to the backwards compatibility feature described above

正如上述声明中,从4.0开始,SDWebImage将依靠 FLAnimatedImage来处理动态图像,所以在4.0及以后的版本使用类似sd_setImageWithURL的方法,只会显示图像的第一帧。

解决办法:
1.导入FLAnimatedImage和SDWebImage/GIF

在podfile文件中添加以下库

pod 'SDWebImage/GIF'
pod 'FLAnimatedImage', '~> 1.0'
终端执行 pod install

2.之后在控制器中引入头文件(只需要引入这一个即可)

 #import "FLAnimatedImageView+WebCache.h"

3.将之前的UIImageView类换成FLAnimatedImageView

测试

 [self.bigImageView sd_setImageWithURL:[NSURL URLWithString:@"https://xxx.org/29.gif"] placeholderImage:nil];

由于FLAnimatedImageView是继承自UIImageView 所以静态图像不受影响;

小demo(https://github.com/tiasn/SDWebImageGiF

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容