SDWebImage 4.0 GIF图片的使用

作者: LiuTianXiang | 来源:发表于2017-07-19 10:30 被阅读3523次

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

相关文章

网友评论

  • Kid_Lee:Gif图,一般比较大,直接使用链接的话,第一次会不会比较慢啊?
    LiuTianXiang:@Kid_Lee 效果是指?图片下载完成才会显示,你意思是添加占位图之类的?
    Kid_Lee:@LiuTianXiang 我知道子线程下载,我的意思是需不需要做预处理,不做预处理的效果好不好?
    LiuTianXiang:@Kid_Lee 子线程下载 不影响UI交互的
  • EdenChow:正点,谢谢楼主的分享。

本文标题:SDWebImage 4.0 GIF图片的使用

本文链接:https://www.haomeiwen.com/subject/ylzkkxtx.html