I'm trying to implement Gesture recognizer over UIWebView to detect double taps. But there is no recognition.
I have looked over web for a few tutorials and I could compile to this. Code below. But there is no success.
class PageContentViewController: UIViewController, UIGestureRecognizerDelegate, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
var pageIndex: Int = 0
var strTitle: String!
var flag : Int = 0
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)
self.view.addSubview(self.webView)
}
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:#selector(self.goToback))
tapGestureRecognizer.delegate? = self
tapGestureRecognizer.numberOfTapsRequired = 2
webView.isUserInteractionEnabled = true
webView.addGestureRecognizer(tapGestureRecognizer)
webView.scrollView.addGestureRecognizer(tapGestureRecognizer)
webView.gestureRecognizerShouldBegin(tapGestureRecognizer)
}
func gestureRecognizer(_: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith:UIGestureRecognizer) -> Bool {
return true
}
func gestureRecognizer(_: UIGestureRecognizer, shouldReceive:UITouch) -> Bool {
return true
}
func goToback(){
print("On the Back")
}
}
What is wrong in the code.?
I'm noob to swift.
Thanks in advance