Disable zoom in WKWebView?
You will have to add maximum scale in script.
The following code should help you:
let source: String = "var meta = document.createElement('meta');" +
"meta.name = 'viewport';" +
"meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';" +
"var head = document.getElementsByTagName('head')[0];" +
"head.appendChild(meta);"
let script: WKUserScript = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
let userContentController: WKUserContentController = WKUserContentController()
let conf = WKWebViewConfiguration()
conf.userContentController = userContentController
userContentController.addUserScript(script)
let webView = WKWebView(frame: CGRect.zero, configuration: conf)
Disable magnification gesture in WKWebView
You can prevent your users from zooming by setting the delegate of your WKWebKit's UIScrollView and implementing viewForZooming(in:)
as in the following:
class MyClass {
let webView = WKWebView()
init() {
super.init()
webView.scrollView.delegate = self
}
deinit() {
// Without this, it'll crash when your MyClass instance is deinit'd
webView.scrollView.delegate = nil
}
}
extension MyClass: UIScrollViewDelegate {
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return nil
}
}
Disable WKWebView zooming
Please try this to disabled zooming for pinch gesture.
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
scrollView.pinchGestureRecognizer?.isEnabled = false
}
Related Topics
An Error Occurred Uploading to the Itunes Store
How to Add a Button with Click Event on Uitableviewcell in Swift
App Store Connect Message: Your Account Will Soon Need to Be Migrated to Federated Auth
Why to Use Tuples When We Can Use Array to Return Multiple Values in Swift
Decrease the Width of the Last Line in Multiline Uilabel
How Does the Whatsapp Web Client Still Work with the Latest iOS Update (Sdk Version 13.0+)
How to Set Aspect Ratio Constraints Programmatically in iOS
Detect If the Application in Background or Foreground in Swift
How to Connect Viewcontroller.Swift to Viewcontroller in Storyboard
How to Have a Dynamic List of Views Using Swiftui
Change Push Notification Sound
Radial Gradient Background in Swift
Layout Attributes Relative to the Layout Margin on iOS Versions Prior to 8.0
Apn (Apple Push Notification) Payload Size Limit
Swiftui - Animations Triggered Inside a View That's in a List Doesn't Animate the List as Well
iOS Getting Location Updates When App Terminated Without Using Significantchange
Keeping the Contentoffset in a Uicollectionview While Rotating Interface Orientation