iOS中g(shù)if圖的顯示方法示例
一、前言
iOS開(kāi)發(fā)中,大部分時(shí)候我們顯示一張靜態(tài)圖就可以了,但是有的時(shí)候?yàn)榱薝I表現(xiàn)更生動(dòng),我就有可能需要展示gif圖來(lái)達(dá)到效果了。
網(wǎng)上找了一下,顯示gif圖的框架找到了兩個(gè)。
- SDWebImage
- YYImage

二、顯示本地gif圖
SDWebImage和YYImage的顯示本地圖片代碼。
//load loacle gif image
- (void)loadLocaleGifImage{
//sdwebimage
[self labelFactoryWithFrame:CGRectMake(0, 80, kScreenWidth, 20) title:@"SDWebImage"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
NSData *gifData = [NSData dataWithContentsOfFile:path];
UIImageView *sdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, kScreenHeight/3)];
sdImageView.image = [UIImage sd_animatedGIFWithData:gifData];
[self.view addSubview:sdImageView];
//yyImage show gif image
[self labelFactoryWithFrame:CGRectMake(0, kScreenHeight/2 - 20, kScreenWidth, 20) title:@"yyImage"];
YYImage *yyimage = [YYImage imageNamed:@"test.gif"];
YYAnimatedImageView *yyImageView = [[YYAnimatedImageView alloc] initWithImage:yyimage];
yyImageView.frame = CGRectMake(0, kScreenHeight/2, kScreenWidth, kScreenHeight/3);
[self.view addSubview:yyImageView];
}
三、加載網(wǎng)絡(luò)的gif圖
SDWebImage和YYImage的加載網(wǎng)絡(luò)圖片代碼。
//download network gif image
- (void)downloadNetworkGifImage{
//sdwebimage
[self labelFactoryWithFrame:CGRectMake(0, 80, kScreenWidth, 20) title:@"SDWebImage"];
FLAnimatedImageView *sdImageView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, kScreenHeight/3)];
[sdImageView sd_setImageWithURL:[NSURL URLWithString:@"http://photocdn.sohu.com/20151214/mp48444247_1450092561460_10.gif"]];
[self.view addSubview:sdImageView];
//yyImage show gif image
[self labelFactoryWithFrame:CGRectMake(0, kScreenHeight/2 - 20, kScreenWidth, 20) title:@"yyImage"];
YYImage *yyimage = [YYImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://photocdn.sohu.com/20151214/mp48444247_1450092561460_10.gif"]]];
YYAnimatedImageView *yyImageView = [[YYAnimatedImageView alloc] initWithImage:yyimage];
yyImageView.frame = CGRectMake(0, kScreenHeight/2, kScreenWidth, kScreenHeight/3);
[self.view addSubview:yyImageView];
}
- (void)labelFactoryWithFrame:(CGRect)frame title:(NSString *)title{
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.font = [UIFont systemFontOfSize:14];
label.text = title;
[self.view addSubview:label];
}
四、Podfile文件內(nèi)容
platform :ios, '10.0' inhibit_all_warnings! target 'GifDemo' do pod 'YYImage' pod 'SDWebImage/GIF' pod 'FLAnimatedImage' end
五、沒(méi)有demo的文章不是好文章
SDWebImage和YYImage框架顯示本地和網(wǎng)絡(luò)gif圖的demo傳送門(mén)
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
iOS中給自定義tabBar的按鈕添加點(diǎn)擊放大縮小的動(dòng)畫(huà)效果
這篇文章主要介紹了iOS中給自定義tabBar的按鈕添加點(diǎn)擊放大縮小的動(dòng)畫(huà)效果的相關(guān)資料,非常不錯(cuò),具有參考解決價(jià)值,需要的朋友可以參考下2016-11-11
MAC中顯示隱藏文件和不顯示隱藏文件的方法(超簡(jiǎn)單)
下面小編就為大家分享一篇MAC中顯示隱藏文件和不顯示隱藏文件的方法(超簡(jiǎn)單),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
iOS數(shù)據(jù)持久化UserDefaults封裝器使用詳解
這篇文章主要為大家介紹了iOS數(shù)據(jù)持久化UserDefaults封裝器使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
iOS App開(kāi)發(fā)中UITextField組件的常用屬性小結(jié)
iOS開(kāi)發(fā)中音頻視頻播放的簡(jiǎn)單實(shí)現(xiàn)方法
iOS10適配之權(quán)限Crash問(wèn)題的完美解決方案

