ios - 如何在 turbolinks-ios 中禁用 UIWebView 的缩放?
<p><p>我正在试验 <a href="https://github.com/turbolinks/turbolinks-ios" rel="noreferrer noopener nofollow">turbolinks-ios</a> <a href="https://github.com/turbolinks/turbolinks" rel="noreferrer noopener nofollow">turbolinks 5</a> 的适配器.</p>
<p>为了有一些 View ,例如一开始的欢迎 View ,感觉更加原生,我想停用一些 <code>UIWebView</code> 功能,例如缩放或选择文本。</p >
<p>如何在 <code>UIWebView</code> 实例上禁用这些功能?</p>
<h2>演示应用程序</h2>
<p>Turbolinks for iOS 有一个演示应用程序,如果这样更容易回答问题,可以用作示例上下文。</p>
<p>可在此处找到演示应用程序:
<a href="https://github.com/turbolinks/turbolinks-ios/tree/master/TurbolinksDemo" rel="noreferrer noopener nofollow">https://github.com/turbolinks/turbolinks-ios/tree/master/TurbolinksDemo</a> </p>
<h2>不起作用:设置 <code>maximumZoomScale</code></h2>
<p><code>UIScrollView</code> 的 <code>maximumZoomScale</code> 的文档如下:</p>
<blockquote>
<p><strong>maximumZoomScale</strong>: 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.</p>
</blockquote>
<p>因此,在 ViewController 中,我尝试设置属性:</p>
<pre><code>// DemoViewController.swift
class DemoViewController: Turbolinks.VisitableViewController {
override func viewDidLoad() {
super.viewDidLoad()
visitableView.webView?.scrollView.maximumZoomScale = 1.0
visitableView.webView?.scrollView.minimumZoomScale = 1.0
}
// ...
}
</code></pre>
<p>但不幸的是,这没有效果。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>可以通过在视口(viewport)元标记上设置 <code>user-scalable=no</code> 在服务器端禁用缩放:</p>
<pre><code><head>
<meta name="viewport" content="width=device-width, user-scalable=no" />
</head>
</code></pre>
<p>作为 <a href="https://stackoverflow.com/a/22544312/2066546" rel="noreferrer noopener nofollow">this stackoverflow answer</a>建议:</p>
<blockquote>
<p><strong>user-scalable=no</strong> ... You use it if you want your web app to feel more like a native app (in terms of zooming).</p>
</blockquote>
<p>有<a href="https://stackoverflow.com/a/37859168/2066546" rel="noreferrer noopener nofollow">some discussion</a>这在 iOS 10 中将不再可能。但根据 <a href="https://beta.applebetas.tk/notes/ios/10.0/beta6.pdf" rel="noreferrer noopener nofollow">release nots of iOS10 beta 6</a> ,现在可以选择加入:</p>
<blockquote>
<p><strong>Safari</strong></p>
<ul>
<li><code>WKWebView</code> now defaults to respecting <code>user-scalable=no</code> from a viewport. Clients of <code>WKWebView</code> can improve accessibility and allow users to pinch-to-zoom on all pages by setting the <code>WKWebViewConfiguration</code> property <code>ignoresViewportScaleLimits</code> to <code>YES</code>.</li>
</ul>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 如何在 turbolinks-ios 中禁用 UIWebView 的缩放?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38927658/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38927658/
</a>
</p>
页:
[1]