WKWebview本身不支持捏合手势,但是如果把WKWebview放到ScrollView上面,由于ScrollView支持捏合手势,导致WKWebview的内容会支持捏合手势。这种情况下要禁止WKWebview捏合手势就需要添加如下代码:
1 2 3 4 5
| - (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation { NSString *javascript = @"var meta = document.createElement('meta');meta.setAttribute('name', 'viewport');meta.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no');document.getElementsByTagName('head')[0].appendChild(meta);"; [webView evaluateJavaScript:javascript completionHandler:nil]; }
|
注意:下面的设置并不能有效禁止捏合手势
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| scrollView.pinchGestureRecognizer.enabled = NO; scrollView.minimumZoomScale = 1; scrollView.maximumZoomScale = 1;
webView.scrollView.pinchGestureRecognizer.enabled = NO; webView.scrollView.minimumZoomScale = 1; webView.scrollView.maximumZoomScale = 1;
- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView { return nil; }
|