iOS開發:SDWebImage4.0之後解決載入gif不顯示問題,iossdwebimage4.0

來源:互聯網
上載者:User

iOS開發:SDWebImage4.0之後解決載入gif不顯示問題,iossdwebimage4.0

之前的使用方法

    UIImageView *imgView = [UIImageView new];    imgView.contentMode = UIViewContentModeScaleAspectFit;    imgView.frame = CGRectMake(0, 0, 100, 30);    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"going" ofType:@"gif"];    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];    imgView.backgroundColor = [UIColor clearColor];    imgView.image = [UIImage sd_animatedGIFWithData:imageData];    [self addSubview:imgView];

SDWebImage4.0之後使用以上的方法顯示gif圖,會顯示不出來。
訪問SDWebImage的github網址

Animated Images (GIF) supportStarting with the 4.0 version, we rely onFLAnimatedImageto take care of our animated images. If you use cocoapods, add pod 'SDWebImage/GIF'to your podfile. To use it, simply make sure you useFLAnimatedImageViewinstead ofUIImageView. Note: there is a backwards compatible feature, so if you are still trying to load a GIF into aUIImageView, it will only show the 1st frame as a static image. Important: FLAnimatedImage only works on the iOS platform. For OS X, useNSImageViewwithanimatesset toYESto show the entire animated images andNOto only show the 1st frame. For all the other platforms (tvOS, watchOS) we will fallback to the backwards compatibility feature described above

使用下面的新方法就可以正常顯示gif

 FLAnimatedImageView *imgView = [FLAnimatedImageView new]; imgView.contentMode = UIViewContentModeScaleAspectFit; imgView.frame = CGRectMake(0, 0, 100, 30); NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"going" ofType:@"gif"]; NSData *imageData = [NSData dataWithContentsOfFile:filePath]; imgView.backgroundColor = [UIColor clearColor]; imgView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; [self addSubview:imgView];

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.