I'm experimenting with the turbolinks-ios adapter for turbolinks 5.
In order to have some view, for example a welcome view right at the beginning, feel even more native, I'd like to deactivate some UIWebView
features like zooming or selecting text.
How can I disable these features on the UIWebView
instance?
Turbolinks for iOS has a demo application that may serve as an example context if this makes it easier to answer the question.
The demo app can be found here: https://github.com/turbolinks/turbolinks-ios/tree/master/TurbolinksDemo
maximumZoomScale
The documentation for UIScrollView
's maximumZoomScale
reads:
maximumZoomScale: A floating-point value that specifies the maximum scale factor that can be applied to the scroll view's content. This value determines how large the content can be scaled. It must be greater than the minimum zoom scale for zooming to be enabled. The default value is 1.0.
Thus, in the view controller, I tried to set the property:
// DemoViewController.swift
class DemoViewController: Turbolinks.VisitableViewController {
override func viewDidLoad() {
super.viewDidLoad()
visitableView.webView?.scrollView.maximumZoomScale = 1.0
visitableView.webView?.scrollView.minimumZoomScale = 1.0
}
// ...
}
But unfortunately, this has no effect.
The zooming can be disabled on the server side by setting user-scalable=no
on the viewport meta tag:
<head>
<meta name="viewport" content="width=device-width, user-scalable=no" />
</head>
As this stackoverflow answer suggested:
user-scalable=no ... You use it if you want your web app to feel more like a native app (in terms of zooming).
There has been some discussion that this would no longer be possible in iOS 10. But according to the release nots of iOS10 beta 6, this is now opt-in:
Safari
WKWebView
now defaults to respectinguser-scalable=no
from a viewport. Clients ofWKWebView
can improve accessibility and allow users to pinch-to-zoom on all pages by setting theWKWebViewConfiguration
propertyignoresViewportScaleLimits
toYES
.