0

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

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;
}
4

1 回答 1

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

于 2017-11-30T09:13:34.417 回答