我在iPad上有一个主窗口xib.主窗口具有轻击手势识别器,当用户点击屏幕时显示/隐藏工具栏.主窗口中还有一个Web视图.
如果用户单击Web视图中的链接,我将如何取消手势?如果他们点击链接,我不希望工具栏切换.
谢谢
您需要检查视图是否应该接收触摸实现:
- (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
}
Run Code Online (Sandbox Code Playgroud)
如果您想使用UITapGestureRecognizer,您需要按照此处的说明对UIWebView进行子类化:https://github.com/psychs/iphone-samples/tree/4028ab78af92ab17465338575b78ed80310a613f/WebViewTappingHack