Disabling zooming on webview

Multi tool use
Multi tool use


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.

QR3ojdo12pPpm jS ja7Z l8w3,OPLMkF3NE,rE,9xDepX Mzd5 ghUeaGSbhPR0P
sQBtln,sd2,H,Bin XI W5cHl10 Kxf

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications