How change min and max zoom scale in WKWebView?

情到浓时终转凉″ 提交于 2019-12-06 10:45:26

问题


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:

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
}

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?

With deprecated UIWebView there was no such problem. (But there was very unpredictable scaling.)


回答1:


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>

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.



来源:https://stackoverflow.com/questions/46289653/how-change-min-and-max-zoom-scale-in-wkwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!