如何在ios 11的webView中禁用缩放/缩放

时间:2017-11-30 08:04:22

标签: ios webview xcode9.1

我想在webview od ios 11中禁用放大缩小。我使用的是xcode 9 在我的AppDelegate.m

1: -

- (void)webViewDidFinishLoad:(UIWebView *)webView {
  webView.scalesPageToFit = NO;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *) scrollView
{
  return nil;
}

2: -

- (void)webViewDidFinishLoad:(UIWebView *)webView {
  webView.scrollView.maximumZoomScale = 1.0;
  webView.scrollView.minimumZoomScale = 1.0;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *) scrollView
{
  return nil;
}

3: -

- (void)hijackWebViewScrollViewDelegate:(UIWebView *)webView {
  UIScrollView *scrollView = (UIScrollView *)[webView.subviews objectAtIndex:0];
  scrollView.delegate = self;//xcode shows error in this is Assigning to 'id<UIScrollViewDelegate> _Nullable' from incompatible type 'AppDelegate *const __strong'**
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  return nil;
}

4: - 我在我的AppDelegate.m中使用这个并在h中应用scrollViewDelegate没有错误但是没有实现。

@implementation AppDelegate


- (void)webViewDidFinishLoad:(UIWebView *)webView {

    webView.scrollView.delegate = self;
    webView.scrollView.maximumZoomScale = 1.0;
    webView.scrollView.minimumZoomScale = 1.0;
    webView.scalesPageToFit = NO;
    webView.multipleTouchEnabled=NO;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *) scrollView
{
  return nil;
}

1 个答案:

答案 0 :(得分:0)

这对我有用。我希望为你工作!!

class ViewController: UIViewController, UIScrollViewDelegate{

    //MARK: UIScrollView Delegate Methods
    func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?){
        scrollView.pinchGestureRecognizer?.isEnabled = false
        //For Avoid Zoom in Webview's content we are disable pinchGestureRecognizer
   }
}


//Objective-C 
//Use below code for Objective-C

-(void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
     [[scrollView pinchGestureRecognizer] setEnabled:false];
 }

注意:不要忘记添加UIScrollviewDelegate