如何在WKWebView中更改最小和最大缩放比例? [英] How change min and max zoom scale in WKWebView?
问题描述
我使用WKWebView来显示svg.它相当大,我需要按捏手势缩放它的支持. WKWebView开箱即用.但.对于最小和最大缩放比例,它具有自己的约束. 例如:
I use WKWebView to show svg. It's rather big and i need support of scaling it on pinch gesture. WKWebView do it out of the box. But. It has it's own constraints for min and max zoom scale. For example:
订阅WKWebView的scrollView委托并实现方法
subscribe to WKWebView's scrollView delegate and implement method
optional func scrollViewDidEndZooming(_ scrollView: UIScrollView,
with view: UIView?,
atScale scale: CGFloat)
{
print(self.wkWebView.scrollView.minimumZoomScale, self.wkWebView.scrollView.maximumZoomScale)
self.wkWebView.scrollView.minimumZoomScale = 0.01
self.wkWebView.scrollView.maximumZoomScale = 20.0
}
在下一个呼叫中它将打印:0.25,5.0.我的(0.01,20.0)值被完全忽略.是纠正它的方法吗?
And in next call it will print: 0.25, 5.0. My values of (0.01, 20.0) are absolutely ignored. Is it a way to correct it?
使用已弃用的UIWebView时,不会出现此类问题. (但是伸缩性非常难以预测.)
With deprecated UIWebView there was no such problem. (But there was very unpredictable scaling.)
推荐答案
我知道这个问题现在已经很老了,但是我正在解决似乎是一个类似的问题,并且认为我的解决方案可能会对其他人有所帮助.我将SVG封装在以下HTML中:
I know this question is old now but I'm tackling what seems to be a similar problem and thought my solution might help others. I've wrapped the SVG in the following HTML:
<html>
<head>
<meta id="mw-viewport" name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1, initial-scale=1.0"/>
</head>
<body>
<svg/>
</body>
</html>
一旦计算出所需的最小/最大缩放级别,我将执行一些JavaScript来抓取"mw-viewport"
元标记并编辑其"content"
属性的"minimum-scale=1, maximum-scale=1"
值.
Once I've calculated my desired min/max zoom levels I execute some javascript to grab the "mw-viewport"
meta tag and edit it's "content"
attribute's "minimum-scale=1, maximum-scale=1"
values.
这篇关于如何在WKWebView中更改最小和最大缩放比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!