Question

I have a UIWebView and I want to detect any touch on that. (I don't want to use UITapGsture or any other thing)

I am using sendEvent: method of UIApplication for this purpose and check if touch object contains webview.

Surprisingly it points to UIWebBrowserView. I have to check it's superview to get browser but it makes my code very inefficient because sendEvent is called every time when user makes a tap.

Code Snippet :

- (void)sendEvent:(UIEvent *)event {
    [super sendEvent:event];

    NSSet *touches = [event allTouches];
    if (touches.count != 1)
        return;
    UITouch *touch = touches.anyObject

    if([touch.view isKindOfClass:[UIWebView class]]){ // This fails

    }
}

I want to know is there a way to make UITouch return WebView as an object instead of returning it's child views like UIPdfView or UIWebBrowser view?

Was it helpful?

Solution

Finally I found a solution to this :

We have to use :

if([touch.view isMemberOfClass:[UIWebView class]]){ // This Works

}

instead of :

if([touch.view isKindOfClass:[UIWebView class]]){ // This fails

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top