如何在 turbolinks-ios 中禁用 UIWebView 的缩放?

How to disable zooming for UIWebView in turbolinks-ios?

我正在试验 turbolinks-ios adapter for turbolinks 5

为了有一些视图,例如一开始的欢迎视图,感觉更原生,我想停用一些 UIWebView 功能,例如缩放或选择文本。

如何在 UIWebView 实例上禁用这些功能?

演示应用程序

iOS 的 Turbolinks 有一个演示应用程序,如果可以更轻松地回答问题,可以用作示例上下文。

可在此处找到演示应用程序: https://github.com/turbolinks/turbolinks-ios/tree/master/TurbolinksDemo

无效:设置maximumZoomScale

UIScrollViewmaximumZoomScale 的文档如下:

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.

因此,在视图控制器中,我尝试设置 属性:

// DemoViewController.swift
class DemoViewController: Turbolinks.VisitableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        visitableView.webView?.scrollView.maximumZoomScale = 1.0
        visitableView.webView?.scrollView.minimumZoomScale = 1.0
    }

    // ...
}

但很遗憾,这没有效果。

可以通过在视口元标记上设置 user-scalable=no 在服务器端禁用缩放:

<head>
  <meta name="viewport" content="width=device-width, user-scalable=no" />
</head>

正如this Whosebug answer建议的那样:

user-scalable=no ... You use it if you want your web app to feel more like a native app (in terms of zooming).

已有some discussion that this would no longer be possible in iOS 10. But according to the release nots of iOS10 beta 6,现在选择加入:

Safari

  • WKWebView now defaults to respecting user-scalable=no from a viewport. Clients of WKWebView can improve accessibility and allow users to pinch-to-zoom on all pages by setting the WKWebViewConfiguration property ignoresViewportScaleLimits to YES.