如何重置UIWebView的缩放?我已经在使用scalesPagesToFit = YES;
过去一周我一直在寻找这个问题的答案。
我有一个 UIWebView,位于 UIScrollView 内部。一切都很好,但我希望 UIWebView 的内容在方向改变时重置其缩放。
在 UIWebView 内的 HTML 中,我将视口的宽度(带元标记)设置为“device-width”,然后在 Obj-C 端设置 scalesPagesToFit = YES;
我尝试过用 javascript 重置缩放;通过在运行时替换元标记;重新加载;访问 UIWebView 内部的 UIScrollView;等等...
但没有成功。
有大神知道解决办法吗?
我唯一能想到的就是每次改变方向时重新创建 UIWebViews,但这会使它们在渲染内容时闪烁为白色,这看起来很糟糕:(
有什么想法吗?
非常感谢, 安德烈
I've been looking for the past week for the answer to this question.
I have a UIWebView, inside of a UIScrollView. Everything works great, but I want the content of the UIWebView to reset its zoom, when the orientation changes.
In the HTML inside the UIWebView, I set the width of the viewport (w/ a meta tag) to "device-width" and then on the Obj-C side, I set the scalesPagesToFit = YES;
I've tried resetting the zoom with javascript; by replacing the meta tags in runtime; reloading; accessing the UIScrollView inside of the UIWebView; etc...
but with no success.
Any of you gods know a workaround?
The only one I can think off is to recreate the UIWebViews every time we change the orientation, but that makes them flash to white whilst rendering content, which looks terrible :(
Any thoughts?
Many thanks,
Andre
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我只是在这里猜测并没有尝试过,但据我所知 UIWebView 有一个 UIScrollView 子项。所以人们应该能够做到:
I'm just guessing here and haven't tried, but AFAIK a UIWebView has a UIScrollView child. So one should be able to do:
在 iOS 5+ 上,您可以访问scrollView。
只需执行:
[webView.scrollView setZoomScale:1.0];
On iOS 5+ you have access to scrollView.
Just do:
[webView.scrollView setZoomScale:1.0];
如果您想以编程方式执行此操作,这是我能找到的唯一方法来完成它:(如果您愿意,请指定您自己的尺寸,我在表单字段中输入内容后尝试缩小)
If you want to do it programmatically this is the only way I could find to accomplish it: (specify your own sizes if you wish, i was attempting to zoom out after typing into a form field)
更新:
使用时缩小尺寸无法正常工作
页面上缩小尺寸的图像质量非常糟糕。正在做:
修复它。所以最后一行是您可以使用的。
webView 是 UIWebView 的子类,它位于某个 IB 文件上。我根本没有使用视口。我发现应该选择从 Cocoa Touch 一侧执行此操作或使用 JS。
我用过:
我想知道是否有办法重置scalesPageToFit。
Update:
Downscaling wasn't working properly when using
The quality of the images being downscaled on the page was awful. Doing:
Fixed it. So that last line is the one you could use.
webView was subclassed of a UIWebView which lies on some IB file. I didn't use the Viewport at all. I find that one should pick by either doing this from the Cocoa Touch side or use JS.
I used:
I wonder if there's a way of resetting the scalesPageToFit.
根据 Captnwalker1 的答案,我想出了这个:
所以加载你的 webview 图像,图像在旋转时将重置其大小。
Adapting from Captnwalker1's answer, I came up with this:
So load your webview image, and the image will reset it's size when rotated.