IOS development: fixed the problem of loading gif without display after SDWebImage4.0. iossdwebimage4.0

Source: Internet
Author: User

IOS development: fixed the problem of loading gif without display after SDWebImage4.0. iossdwebimage4.0

Previous usage

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

After SDWebImage4.0, you can use the above method to display gif images.
Visit SDWebImage's github URL

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

Use the following new method to display gif images.

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.