亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

iOS中gif圖的顯示方法示例

 更新時間:2019年06月14日 10:35:46   作者:藍光95  
這篇文章主要給大家介紹了關于iOS中gif圖的示的相關資料,文中通過示例代碼介紹的非常詳細,對各位iOS開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧

一、前言

iOS開發(fā)中,大部分時候我們顯示一張靜態(tài)圖就可以了,但是有的時候為了UI表現更生動,我就有可能需要展示gif圖來達到效果了。

網上找了一下,顯示gif圖的框架找到了兩個。

  • 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];
}

三、加載網絡的gif圖

SDWebImage和YYImage的加載網絡圖片代碼。

//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文件內容

platform :ios, '10.0'
inhibit_all_warnings!

target 'GifDemo' do

pod 'YYImage'
pod 'SDWebImage/GIF'
pod 'FLAnimatedImage'

end

五、沒有demo的文章不是好文章

SDWebImage和YYImage框架顯示本地和網絡gif圖的demo傳送門

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。

相關文章

  • flutter狀態(tài)管理Provider的使用學習

    flutter狀態(tài)管理Provider的使用學習

    這篇文章主要為大家介紹了flutter狀態(tài)管理Provider的使用學習,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • iOS開發(fā)中UITabBarController的使用示例

    iOS開發(fā)中UITabBarController的使用示例

    這篇文章主要介紹了iOS開發(fā)中UITabBarController的使用示例,代碼基于Objective-C進行演示,需要的朋友可以參考下
    2015-09-09
  • SIGPIPE(Signal?13,?Code?0)?異常排查及處理

    SIGPIPE(Signal?13,?Code?0)?異常排查及處理

    這篇文章主要為大家介紹了SIGPIPE(Signal?13,?Code?0)?異常排查原因解析及處理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • iOS App開發(fā)中UIViewController類的使用教程

    iOS App開發(fā)中UIViewController類的使用教程

    UIViewController是iOS中控制視圖的關鍵所在,這里我們將針對UIViewController的聲明周期與主要屬性和方法,來總結iOS App開發(fā)中UIViewController類的使用教程
    2016-07-07
  • UITableView中Cell重用機制導致內容重復的解決方法

    UITableView中Cell重用機制導致內容重復的解決方法

    這篇文章主要為大家詳細介紹了UITableView中Cell重用機制導致內容重復的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • iOS實現后臺長時間運行

    iOS實現后臺長時間運行

    這篇文章主要為大家詳細介紹了iOS實現后臺長時間運行,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • iOS基于UITableView實現多層展開與收起

    iOS基于UITableView實現多層展開與收起

    這篇文章主要為大家詳細介紹了iOS基于UITableView實現多層展開與收起的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • ios獲取數據之encodeURI和decodeURI的實例

    ios獲取數據之encodeURI和decodeURI的實例

    下面小編就為大家?guī)硪黄猧os獲取數據之encodeURI和decodeURI的實例。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • iOS中的ipa重簽名(逆向必備)

    iOS中的ipa重簽名(逆向必備)

    這篇文章給大家介紹了ios中的ipa重簽名知識以及錯誤原因及解決俄方案,需要的朋友參考下吧
    2018-01-01
  • 學習iOS全局跑馬燈

    學習iOS全局跑馬燈

    這篇文章主要幫助大家學習iOS全局跑馬燈,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10

最新評論