UIWebview缩放PDF和大型。图像缩放默认情况下,IOS [英] UIWebview Zooming PDF and Large . Images Zoom By defaults IOS
问题描述
我正在使用 UIWebView
来加载具有缩放功能的PDF和图像。
为此,我检查了 webView.scalesPageToFit
属性为true,它运行正常。
I am using UIWebView
to load PDF and images with zooming functionality .
For that I checked webView.scalesPageToFit
Property to true and it is working fine .
但我的问题是
当我加载大图像(2496 * 3507)时,它默认显示放大我不希望我想要大小适合
When I load large Images (2496 * 3507) it shows by default Zoomed that I don't want I want size to fit
要克服这个问题
我实现了Web视图委托以下代码
I implemented Web view delegate with following code
func webViewDidFinishLoad(_ webView: UIWebView) {
webView.contentMode = .scaleAspectFit
let zoom = webView.bounds.size.width / webView.scrollView.contentSize.width
webView .stringByEvaluatingJavaScript(from: "document.body.style.zoom = \(zoom);")
}
现在解决了默认缩放问题,但webview允许垂直和水平滚动
Now the issue of Default zoom is resolved but webview allows to scroll to vertically and horizontally
推荐答案
您可以使用下面的代码停止scrollView以垂直和水平滚动。你也可以停止反弹。
You can stop scrollView to scroll Vertically and Horizontally using below code. You can also stop bounces.
webView.scrollView.bounces = false;
webView.scrollView.isScrollEnabled = false;
这篇关于UIWebview缩放PDF和大型。图像缩放默认情况下,IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!