一般有很多种方法,一般是以下三种:
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会避免这个问题
怎么禁止webview缩放:
1.继承delegate:UIScrollViewDelegate
webView.scrollView.delegate = self;
2.核心,禁用了scrollview的手势
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
[scrollView.pinchGestureRecognizer setEnabled:NO];
[scrollView.panGestureRecognizer setEnabled:NO];
}
参考:
https://stackoverflow.com/questions/25553711/disable-magnification-gesture-in-wkwebview?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa