这就是我想做的事情
- (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;
}
问题是代码总是选择"we went with no"
的路径,无论我在哪里实际挖掘。如何解决我的问题?
答案 0 :(得分:2)
如果您在特定视图外点击时发现手势识别器操作正在触发,则应仔细检查是否正确添加了手势识别器。
[self.myView addGestureRecognizer:[[UIGestureRecognizer alloc] initWithTarget:self action:@selector(someAction:)]];
如果您仍然遇到错误的操作火灾,您可以检查触摸位置。
if (CGRectContainsPoint(self.myView.bounds, [gesture locationInView:self.myView]))