从4.0开始,SDWebImage将依靠 FLAnimatedImage来处理动态图像,所以在4.0及以后的版本使用类似sd_setImageWithURL
的方法,只会显示一张静态图片。
解决办法:
一、如果你用的是pod:
1.导入FLAnimatedImage和SDWebImage/GIF
pod 'SDWebImage/GIF'
pod 'FLAnimatedImage
终端执行 pod install
2.将之前的UIImageView类换成FLAnimatedImageView
[self.xxImageView sd_setImageWithURL:[NSURL URLWithString:@"url.gif"] placeholderImage:nil];
二、如果你直接导入代码
现在这个库中已经导入了FLAnimatedImage和SDWebImage/GIF,用的时候,只需要导入头文件:
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
#import <SDWebImage/UIView+WebCache.h>
然后重复上边的2就行了
三、加载本地gif
NSString *path = [[NSBundle mainBundle] pathForResource:@"LiveVideoNewIMG1" ofType:@"gif"];
NSData *gifData = [NSData dataWithContentsOfFile:path];
XXImage.image=[UIImage sd_animatedGIFWithData:gifData];
本地的我没有试过。