[IOS] How to use gif

There are generally many methods, generally the following three:

1. Use a third-party framework

2.用UIWebView

3. Play multiple pictures with animation

 

Here is mainly the second one:

Read the gif:

NSString *imageName = [[NSString alloc] initWithFormat:@"t%d_xxxh",i + 1];
NSString *pathEnd = [[NSBundle mainBundle] pathForResource:imageName ofType:@"gif"];
NSData *data = [NSData dataWithContentsOfFile:pathEnd];

 Load with UIWebView:

webView.frame = CGRectMake(width/10, 5, width/5*4, width/5*4);
webView.scalesPageToFit = YES;
webView.scrollView.scrollEnabled  = NO;
[webView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[view addSubview:webView];

 

Why choose webview, because using a third-party framework to find that loading high-definition images can easily lead to crash, using webview will avoid this problem

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325976957&siteId=291194637