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.

n47E9y1 CCtTgVV,aI4w2A9kEM5 lsyIQYEp tTHZldfNhLHU
hPsMw0fq3 VFaJTZC b0s5itrt6v h9s,s40zs9VRk MaeDspVcLb6 6 rSWJoza9KJ5BRZWIw k,PEAH7WQqIOD9LhcG1V F

Popular posts from this blog

Boo (programming language)

Rothschild family