答案 0 :(得分:2)
您可以使用CSS属性-webkit-tap-highlight-color
禁用它:
import UIKit
import WebKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let wv = WKWebView(frame: view.bounds)
view.addSubview(wv)
wv.load(URLRequest(url:URL(string: "https://www.google.com")!))
wv.navigationDelegate = self
}
}
extension ViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let script = "function addStyleString(str) {" +
"var node = document.createElement('style');" +
"node.innerHTML = str;" +
"document.body.appendChild(node);" +
"}" +
"addStyleString('* {-webkit-tap-highlight-color: rgba(0,0,0,0);}');"
webView.evaluateJavaScript(script)
}
}
答案 1 :(得分:1)
与上一个答案类似,但略短一些,您可以改用透明颜色。
extension ViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.body.style.webkitTapHighlightColor='transparent';")
}
}
希望对别人有帮助!