我也遇到过同样的问题。borrrden 是对的;要修复它,请将 viewController 设置为 gestureRecognizer 的委托,如果触摸在 IUButton 上,则取消触摸。首先在 .h 文件中添加协议 `UIGestureRecognizerDelegate。然后,在创建手势识别器之后,将视图控制器设置为其委托:
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(aMethod)];
gestureRecognizer.delegate = self;
[self.view addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];
最后覆盖shouldReceiveTouch
并取消不需要的触摸:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[UIButton class]]) { //Do not override UIButton touches
return NO;
}
return YES;
}