本地GIF加载
之前使用(sd_animatedGIFWithData:imageData)加载本地gif图片,升级了之后发现加载出来的是空白,网上好多让导入pod 'SDWebImage/GIF',导入后发现不能找到"SDWebImage/GIF"
看了SDWebImage发现它的api又又又更新了!!!,上面操作是4.0之后的解决办法,现在SDWebImage5.0之后又有了新变化
5.0以后,SDWebImage为了让核心项目少一些,将FLAnimatedImage分离出去,FLAnimatedImage有自己的repo
pod 'SDWebImage'
pod 'FLAnimatedImage'
pod 'SDWebImageFLPlugin' # 对FLAnimatedImage和SDWebImage的桥接
SDWebImageFLPlugin引入项目中
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
本地GIF代码
FLAnimatedImageView *imgView = [FLAnimatedImageView new];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.frame = CGRectMake(20, 100, 100, 80);
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"gift_banner" ofType:@"gif"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
imgView.backgroundColor = [UIColor clearColor];
imgView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];
[self.view addSubview:imgView];
网络GIF
FLAnimatedImageView *imgView = [FLAnimatedImageView new];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.frame = CGRectMake(20, 100, 100, 80);
[self.view addSubview:imgView];
[imgView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.gif"]];
使用placeholder并加载GIF
FLAnimatedImageView *imageView;
FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:gifData];
SDFLAnimatedImage *placeholder = [[SDFLAnimatedImage alloc] initWithAnimatedImage:animatedImage];
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.gif"] placeholderImage:placeholder];
swift版本
let imageView: FLAnimatedImageView
imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.gif"))
//placeholder并加载GIF
let imageView: FLAnimatedImageView
let animatedImage = FLAnimatedImage(animatedGIFData: gifData)
let placeholder = SDFLAnimatedImage(animatedImage: animatedImage)
imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.gif"), placeholderImage: placeholder)