0

I am using UIWebView to display pdf. I wanna handle touch events on webview. There are two conditions, my WebView should handle double touch events and gestures, and i wanna pass single tap/touch events to super view.

Can any one please tell me how to differentiate the touch events in UIWebView and how to pass specific touch events to its super view?

to get the touch events i am subclassing the uiwebview and im overriding the hitTest method in subclass.

willcodejavaforfood
  • 43,223
  • 17
  • 81
  • 111
CKT
  • 1,223
  • 4
  • 21
  • 39
  • it seems to be a duplicate of this post: http://stackoverflow.com/questions/990870/handling-touches-inside-uiwebview – William Niu Aug 04 '10 at 05:57

2 Answers2

1

If that post is not answering your question, you should check out this article.

I took a similar but slightly different approach: I subclassed a UIView, which contains a UIWebView (and other controls), and override the hitTest:withEvent: method.

William Niu
  • 15,798
  • 7
  • 53
  • 93
0

Subclass web view and Use hitTest(_ point: CGPoint, with event: UIEvent?) method in subclass as follows:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    if let hitTestingView = super.hitTest(point, with: event) {
        if shouldHandleTouch // Logic on which this view should handle touch or not. If you don't want to handle always then return nil {
            return hitTestingView
        } else {
            return nil
        }  
    } else {
        return nil
    }
}
vicky
  • 21
  • 1
  • 5