Add a UITapGestureRecognizer to a UIWebView

user768339 picture user768339 · May 24, 2011 · Viewed 16k times · Source

In iOS, is it possible to put a tap recognizer on a UIWebView, so that when someone single-taps the web view, an action gets performed?

Code below doesn't seem fire handleTap when I tap my webView.

Thanks.

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                      action:@selector(handleTap)];
tap.numberOfTapsRequired = 1;

[webView addGestureRecognizer:tap];
[tap release]; 


-(void) handleTap {
    NSLog(@"tap");
}

Answer

Bryan picture Bryan · Feb 4, 2012

I found that I had to implement this method to get it to work:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}