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 所以静态图像不受影响;