When set webView.allowsLinkPreview = true
, links support 3D touch peek & pop feature. The only problem is the new page will open in Safari instead of the webView
.
According to Apple iOS 10 introduced a new API for WKWebView allowing you to intercept the peek and pop actions of the link preview by using the following delegate methods:
optional func webView(_ webView: WKWebView, previewingViewControllerForElement elementInfo: WKPreviewElementInfo, defaultActions previewActions: [WKPreviewActionItem]) -> UIViewController?
optional func webView(_ webView: WKWebView, commitPreviewingViewController previewingViewController: UIViewController)
Just use the second delegate method to present the url in your own tab or load it in your own WKWebView.