[IOS]如何使用gif

一般有很多种方法,一般是以下三种:

1.是用第三方框架

2.用UIWebView

3.用动画播放多张图

这里主要说第二种:

读取gif:

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

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

为什么选择webview,因为用第三方框架发现加载高清图很容易导致crash,用webview会避免这个问题

猜你喜欢

转载自jameskaron.iteye.com/blog/2422260