本文介绍了你如何阻止 UITapGestureRecognizer 捕捉到每一次点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有一个 opengl 视图,上面有一个标签栏.我正在使用点击识别器点击屏幕上的不同 3d 对象.在选项卡栏中,我有一个按钮,但它不起作用,因为点击识别器也会捕获这些点击.我该如何阻止?我已经试过了:
Hello I have an opengl view and on that I have a tab bar. I'm using a tap recognizer to tap different 3d objects on screen. In the tab bar I have a button but it doesn't work because the tap recognizer catches these taps too. How do I stop this? I've already tried this:
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isKindOfClass:[UIBarButtonItem class]]) return FALSE;
return TRUE;
}
我想我以某种方式比较了错误的类,因为当我调试时它总是返回 TRUE.
I think I am somehow comparing wrong classess because when I debug it returns TRUE always.
推荐答案
或者你可以只做 [singleTap setCancelsTouchesInView:NO]
.示例:
Or you can just do [singleTap setCancelsTouchesInView:NO]
. Example:
UITapGestureRecognizer *singleTap = [
[UITapGestureRecognizer alloc]
initWithTarget: self
action: @selector(yourSelector:)
];
[singleTap setCancelsTouchesInView:NO];
[[self view] addGestureRecognizer: singleTap];
这篇关于你如何阻止 UITapGestureRecognizer 捕捉到每一次点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!