即使将scalesPageToFit设置为YES后,UIWebview也不会缩放
当用户选择 UISegmentedControl
上的选项卡时,我有一个 UIWebview
作为子视图加载。由于某种原因,我无法让它允许捏合/缩放。 我在 viewDidLoad: 方法中设置了以下代码,因此它应该可以工作。
self.myWebView = [[[UIWebView alloc] initWithFrame:self.view.frame] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: myWebView];
我尝试从 NIB 加载 UIWebView
并以编程方式创建它,但没有成功。我有什么遗漏的吗?是什么导致 webview 忽略捏合和缩放?
谢谢!
I have a UIWebview
that is loaded as a subview when a user selects a tab on a UISegmentedControl
. For some reason, I can not get it to allow pinch/zooming
.
I set the following code in the viewDidLoad:
method, so it should work.
self.myWebView = [[[UIWebView alloc] initWithFrame:self.view.frame] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: myWebView];
I tried loading a UIWebView
from a NIB and creating it programmatically with no avail. Is there something I'm missing? What could be causing the webview to ignore pinching and zooming?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据我的经验,您需要在 UIWebView 加载之前设置scalesPageToFit。这意味着在 viewDidLoad 等之前进行设置。我所做的是将其设置在“shouldStartLoadWithRequest”中。
我对文档的解释是,scalesPageToFit 属性指示页面将如何加载。它不会在事后改变事情。
希望这有帮助。
In my experience, you need to set scalesPageToFit before the UIWebView loads. This means setting before viewDidLoad etc. What I do is set it in "shouldStartLoadWithRequest"
My interpretation of the documentation is that the scalesPageToFit property dictates how the page WILL be loaded. It does not alter things after the fact.
Hope this helps.
仅供参考:
可以工作,但
在 iPhone 上不起作用。文档说使用是/否。我想在这种情况下情况很重要。在 obj-c 中,值为 YES/NO 和 1/0
FYI:
works but
does not on the iPhone. The documentation says to use yes/no. I guess case matters in this case. In obj-c the values are YES/NO and 1/0
您必须启用多点触控。捏合涉及屏幕上的多个手指:
[myWebView setMultipleTouchEnabled:YES]
You have to enable multi-touch. Pinch involves more than one finger on the screen:
[myWebView setMultipleTouchEnabled:YES]
这是 Apple 在 webview 类参考中建议的内容。
This is what Apple suggests in the webview class reference.
似乎是合适的解决方案
seem to be the suitable solution
我通过设置视口解决了这个问题:
祝你好运
I solved this with setting a view port:
Good luck
我看到您正在设置
autoresizingMask
。这是否意味着您创建了初始大小为 CGRectZero 的UIWebView
?您可以与文档进行交互吗?我的意思是,滚动/点击有效吗?I see you are setting the
autoresizingMask
. Does that mean you have created theUIWebView
with an initial size ofCGRectZero
? Can you interact with the document at all? I mean, does scrolling/tapping work?