Disabling zooming on webview


Disabling zooming on webview



I've searched around, but I couldn't find how to disable zooming in iOS.



I have this in my viewDidLoad() but it doesn't do anything.


viewDidLoad()


webView.scrollView.isMultipleTouchEnabled = false;



Any ideas?




2 Answers
2



You can disable zooming like this:


webView.scalesPageToFit = NO;
webView.multipleTouchEnabled = NO;





I'm trying to disable zooming though, not scrolling
– Sam
5 hours ago





@Sam Sorry, I misread the question.
– hev1
5 hours ago





no worries, but isn't this Obj-C? Cause they spew errors saying: Value of type 'WKWebView' has no member 'scalesPageToFit' Cannot assign value of type 'ObjCBool' to type 'Bool'
– Sam
5 hours ago



You can remove the pinchGestureRecognizer from scrollView in delegate method didFinish navigation by conforming your ViewController to WKNavigationDelegate as below,


pinchGestureRecognizer


scrollView


didFinish navigation


ViewController


WKNavigationDelegate


class ViewController: UIViewController, WKNavigationDelegate {

var webView: WKWebView!

override func viewDidLoad() {
super.viewDidLoad()

// TODO: Initialize webView before setting the delegate
webView.navigationDelegate = self
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if let pinchGesture = webView.scrollView.pinchGestureRecognizer {
webView.scrollView.removeGestureRecognizer(pinchGesture)
}
}
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to make file upload 'Required' in Contact Form 7?

Rothschild family

amazon EC2 - How to make wp-config.php to writable?