Do not pinch / zoom

I'm new to developing and an amateur to say the least.

I exported a html from Tumult Hype, inserted it in Xcode 9.3, everything works fne on my iPad, except the whole scene is zoomable/pinchable and it should NOT be zoomable.

I used the following with ObjectiveC, is there something similar with swift [self.webview setScalesPageToFit:NO];

I have tried everything I can think of. Any help would be appreciated. Thanks ahead of time.

Here is it is:

import UIKit

import WebKit

class ViewController: UIViewController, WKNavigationDelegate {

override func viewDidLoad() {

super.viewDidLoad()

let webView = WKWebView()

let htmlPath = Bundle.main.path(forResource: "Zimt_09_03", ofType: "html")

let folderPath = Bundle.main.bundlePath

let baseUrl = URL(fileURLWithPath: folderPath, isDirectory: true)

do {

let htmlString = try NSString(contentsOfFile: htmlPath!, encoding: String.Encoding.utf8.rawValue)

webView.loadHTMLString(htmlString as String, baseURL: baseUrl)

} catch {

}

webView.navigationDelegate = self

view = webView

webView.scrollView.isScrollEnabled = false;

webView.scrollView.bounces = false;


// the following commands do not work for me


/* func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {

scrollView.pinchGestureRecognizer?.isEnabled = false

scrollView.panGestureRecognizer.isEnabled = false

}

*/

/*func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {

scrollView.pinchGestureRecognizer?.isEnabled = false

}

*/


/*func viewForZooming(in scrollView: UIScrollView) -> UIView? {

return nil

}

*/

}

}

Replies

The UIwebView property in Swift is :


var scalesPageToFit: Bool


UIWebView documentation states:

If

true
, the webpage is scaled to fit and the user can zoom in and zoom out. If
false
, user zooming is disabled. The default value is
false
.


In case of WKWebView, I'm not sure this porperty exists.

You could try to use : allowsMagnification

But here again,

The default value is

false
. You can set the
magnification
property even if
allowsMagnification
is set to
false
.

So, I would try to insert the following in viewDidLoad:

        webView.allowsMagnification = false;


If that does not fit, you could set Zoom scale of scrollView min and max to 1.0

var maximumZoomScale: CGFloat

A floating-point value that specifies the maximum scale factor that can be applied to the scroll view's content.

var minimumZoomScale: CGFloat

A floating-point value that specifies the minimum scale factor that can be applied to the scroll view's content.


in viewDidLoad:

        webView.scrollView.maximumZoomScale = 1.0
        webView.scrollView.minimumZoomScale = 1.0