UIWebView and Canceling Tap Gestures
I have a main window xib on an iPad. The main window has tap gesture recognizers that show/hide a toolbar when 开发者_运维问答the user taps the screen. There is also a web view in the main window.
How would I go about canceling the gestures if the user clicks a link in the web view? I don't want the toolbar to toggle if they hit a link.
Thanks
You need to check if the view should receive the touch implementing:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if (self.view.superview != nil) {
if ([touch.view isKindOfClass:[UIWebView class]]) {
// we touched our UIWebView
return NO; // ignore the touch
}
}
return YES; // handle the touch
}
If you want to use the UITapGestureRecognizer you need to subclass the UIWebView as explained here: https://github.com/psychs/iphone-samples/tree/4028ab78af92ab17465338575b78ed80310a613f/WebViewTappingHack
精彩评论