Sdwebimage playing GIF images

Source: Internet
Author: User

There are several ways to play GIF images

1. Can play directly with ImageView frame one frame

2. You can use WebView to load a page to play

.

.

.

But their shortcomings are more obvious, will lose frames, if the figure is more than most words, but also may be on the screen is relatively small device can not be fully displayed,

Sdwebimage provides a great way to import a GIF-only header file, which can be implemented in just a few lines of code. The sample code is as follows:

#import "ViewController.h"
#import "Uiimage+gif.h"
@interface Viewcontroller ()
@property (Nonatomic,strong) Uiimageview *loadingimageview;
@end

@implementation Viewcontroller

-(void) Viewdidload {
[Super Viewdidload];
[Self initloadingimageview];
}

-(void) Initloadingimageview
{

NSString *name = @ "4 upgrade. gif";
NSString *filepath = [[NSBundle bundlewithpath:[[nsbundle Mainbundle] Bundlepath]] pathforresource:name OfType:nil];
NSData *imagedata = [NSData Datawithcontentsoffile:filepath];

if (!self.loadingimageview) {
Self.loadingimageview = [[Uiimageview alloc]init];
}
Self.loadingImageView.backgroundColor = [Uicolor Clearcolor];

self.loadingImageView.image = [UIImage sd_animatedgifwithdata:imagedata];
Self.loadingImageView.frame = CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height);

[Self.view AddSubview:self.loadingImageView];

[Self.view BringSubviewToFront:self.loadingImageView];

}
@end

Sdwebimage playing GIF images

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.