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