[iOS] How to detect touch on UIWebView Ask

class ViewController: UIViewController, UIGestureRecognizerDelegate, UIWebViewDelegate  {

@IBOutlet weak var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    webView.delegate = self

    DispatchQueue.main.async {
        let req = URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: self.strTitle+"/index" , ofType: "html")!))
        self.webView.loadRequest(req)
    }

    let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:#selector(self.goToback))
    tapGestureRecognizer.delegate = self
    tapGestureRecognizer.numberOfTapsRequired = 2
    webView.isUserInteractionEnabled = true
    webView.addGestureRecognizer(tapGestureRecognizer)
}


func gestureRecognizer(_: UIGestureRecognizer,  shouldRecognizeSimultaneouslyWith:UIGestureRecognizer) -> Bool {
    return true
}


func goToback() {
    print("On the Back")
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *