iOS SDWebImage加載本地以及網(wǎng)絡(luò)gif圖片

本地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)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容