为 iOS 个应用禁用 3D 触控

Disable 3D touch for iOS application

我有一个呈现 webView 的应用程序。

这个 WebView 存在 link 个我想自己处理的。

使用委托方法一切都很好,但是当用户使用强制触摸时我遇到了问题。在那种情况下,iOS 正在通过 safari 过渡到 link,而不去听我的委托。

我的问题是 - 如何从我的应用程序中删除强制触摸?

谢谢

我相信这就是您要找的:

func webView(_ webView: WKWebView, shouldPreviewElement elementInfo: WKPreviewElementInfo) -> Bool {
    return false
}

它是 WKUIDelegate 中的一个委托方法,是在 iOS10 中添加的。这将禁用强制触摸预览。

根据此 WebKit postallowsLinkPreview 在 iOS 9 上默认为 false,在 iOS 10+

上默认启用

WebKit supports Peek and Pop as an easy way to preview links. Apps built against the iOS 10 SDK will have Peek and Pop link preview enabled by default, but the feature is not new; since iOS 9, WKWebView clients could opt into Peek-based link previews on 3D Touch-capable devices using the allowsLinkPreview property on WKWebView. When the allowsLinkPreview property is set to true, users can gently press on links to peek them, which loads the link in another view over the app and blurs the app in the background.

尝试将其设置为 false

从 Web 视图中删除 3d touch 的方法是 -

yourWebView.allowsLinkPreview = false