Ios 检查哪个视图发送手势识别器

Ios 检查哪个视图发送手势识别器,ios,uiview,uigesturerecognizer,Ios,Uiview,Uigesturerecognizer,这就是我想做的 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if (touch.view != self.myView) { NSLog(@"we went with no"); //don't let anything that's not myView fire the gesture r

这就是我想做的

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (touch.view != self.myView) {
        NSLog(@"we went with no");
        //don't let anything that's not myView fire the gesture recognizer
        return NO;
    }
    NSLog(@"we went with yes");
    return YES;
}

问题是代码总是选择路径
“我们没有去”
,不管我在哪里实际点击。如何修复我的if检查?

如果您在特定视图外点击时发现您的手势识别器动作正在启动,则应再次检查是否正确添加了手势识别器

[self.myView addGestureRecognizer:[[UIGestureRecognizer alloc] initWithTarget:self action:@selector(someAction:)]];
如果您仍然遇到不正确的动作射击,您可以检查触摸位置

if (CGRectContainsPoint(self.myView.bounds, [gesture locationInView:self.myView]))

touch.view
是触摸产生的视图,可能不是当前视图。考虑到这一点,
touch.view
是否会返回
self.myView
的子视图?您是否尝试过检查触摸屏返回的内容?如果它是子视图,请尝试类似于
isDescendatoView: