ios 禁用 UIWebView 的放大缩小功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9628293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:14:33  来源:igfitidea点击:

Disabling zoom-in zoom-out functionality of the UIWebView

iosuiwebview

提问by user1036201

I am new to iOS development and I am developing an application which will show and web page in UIWebView. I want to get rid of the default zoom-inand zoom-outfunctionality of the webview.

我是 iOS 开发的新手,我正在开发一个应用程序,它将在UIWebView. 我想摆脱默认的zoom-inzoom-out的功能webview

回答by JTApps

This is in the Apple Documentation:

这是在Apple文档中:

@property(nonatomic) BOOL scalesPageToFit
Discussion
If YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.

Interface Builder Approach:

界面生成器方法:

  1. Make sure that the "Scale pages to fit" tick box in the right-side column of the interface builder when you click on your webview is un-ticked. It's right at the top.

  2. You're also going to need to un-tick the box that says "Multiple Touch" around half way down. That will disable pinching to zoom.

  1. 确保当您单击 webview 时,界面构建器右侧列中的“缩放页面以适应”复选框未被选中。它就在顶部。

  2. 你也要去需要取消选中,上面写着“多触摸”在半路把箱子。这将禁用捏缩放。

Code Approach:

代码方法:

You can also do it programmatically with this code:

您也可以使用以下代码以编程方式执行此操作:

webView.scalesPageToFit = NO;

You're also going to want to add:

您还需要添加:

webView.multipleTouchEnabled = NO;

That will disable the ability to pinch and zoom, since it disables the ability to use multiple fingers in an action, and pinching requires two, obviously!

这将禁用捏合和缩放的能力,因为它禁用了在一个动作中使用多个手指的能力,显然捏合需要两个!

回答by Wubao Li

set the UIWebView property scalesPageToFit to NO, will disable the user zooming

将 UIWebView 属性 scalesPageToFit 设置为 NO,将禁用用户缩放

myWebView.scalesPageToFit = NO;

回答by JTApps

One simply needs to do:

一个只需要做:

myWebView.scalesPageToFit = NO;

myWebView.scalesPageToFit = NO;

and also disable the pesky pinch to zoom:

并禁用讨厌的捏缩放:

webView.multipleTouchEnabled = NO;

webView.multipleTouchEnabled = NO;

回答by Chinmay Das

UIScrollView *scrollView = [webView.subviews objectAtIndex:0];
scrollView.delegate = self;//self must be UIScrollViewDelegate

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

try this ... It works..

试试这个......它有效......

回答by Alessandro Francucci

Swift Solution

快速解决方案

Simply set the value mentioned above to false: webView.scalesPageToFit = false

只需将上面提到的值设置为 false: webView.scalesPageToFit = false

回答by Safeen Azad

Disable bouncesZoom of the scrollView will solve your problem. Give it a try!

禁用滚动视图的bouncesZoom 将解决您的问题。试一试!

webView.scrollView.bouncesZoom = false

回答by Leslie Godwin

When inheriting from UIWebView you can implement. (Works from iOS 5, lower not sure)

从 UIWebView 继承时,您可以实现。(适用于 iOS 5,较低的不确定)

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

回答by Sridhara Shetty

Try this:

尝试这个:

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

回答by Kelsey

To add to the answers, this will work:

要添加到答案中,这将起作用:

webView.scrollView.multipleTouchEnabled = NO;

回答by Hari Narayanan

i am also struggle at first when i use webview scroll event after that i fond the below code for disable the scroll in webview and this also remove the multitouch gestures function in that particular webview.

起初我也很挣扎,当我使用 webview 滚动事件之后,我喜欢下面的代码来禁用 webview 中的滚动,这也删除了该特定 webview 中的多点触控手势功能。

[[[theWebView subviews] lastObject] setScrollEnabled:NO];

[[[theWebView subviews] lastObject] setScrollEnabled:NO];

here theWebView is the name of my UIWebView.. use this code in webViewDidFinishLoad function ,,, its really helpful to me,..

这里 theWebView 是我的 UIWebView 的名称 .. 在 webViewDidFinishLoad 函数中使用此代码,,它对我真的很有帮助,..