SDWebImage 官方說(shuō)明
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開(kāi)始,SDWebImage將依靠 FLAnimatedImage來(lái)處理動(dòng)態(tài)圖像,所以在4.0及以后的版本使用類(lèi)似sd_setImageWithURL
的方法,只會(huì)顯示圖像的第一幀。
解決辦法:
1.導(dǎo)入FLAnimatedImage和SDWebImage/GIF
在podfile文件中添加以下庫(kù)
pod 'SDWebImage/GIF'
pod 'FLAnimatedImage', '~> 1.0'
終端執(zhí)行 pod install
2.之后在控制器中引入頭文件(只需要引入這一個(gè)即可)
#import "FLAnimatedImageView+WebCache.h"
3.將之前的UIImageView類(lèi)換成FLAnimatedImageView
測(cè)試
[self.bigImageView sd_setImageWithURL:[NSURL URLWithString:@"https://xxx.org/29.gif"] placeholderImage:nil];
由于FLAnimatedImageView是繼承自UIImageView 所以靜態(tài)圖像不受影響;