本地GIF加載
之前使用(sd_animatedGIFWithData:imageData)加載本地gif圖片,升級了之后發(fā)現(xiàn)加載出來的是空白,網(wǎng)上好多讓導(dǎo)入pod 'SDWebImage/GIF',導(dǎo)入后發(fā)現(xiàn)不能找到"SDWebImage/GIF"

找不到
看了SDWebImage發(fā)現(xiàn)它的api又又又更新了?。?!,上面操作是4.0之后的解決辦法,現(xiàn)在SDWebImage5.0之后又有了新變化

5.0之后,SDWebImage為了讓核心項目少一些,將FLAnimatedImage分離出去
5.0以后,SDWebImage為了讓核心項目少一些,將FLAnimatedImage分離出去,F(xiàn)LAnimatedImage有自己的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];
網(wǎng)絡(luò)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)