我有以下代码,我将UITapGestureRecognizer添加到我的视图中:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(userTapped)];
[self.view addGestureRecognizer:tap];
我的问题是,当我按下与UIButton
在同一视图上的其他UITapGestureRecognizer
(按钮在IB中创建)时,没有任何反应。
我想我只在一个动作(userTapped :)中添加了一个动作(userTapped :),但是如何添加与创建的其他按钮的交互?
答案 0 :(得分:6)
尝试
tap.cancelsTouchesInView = NO;
或
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if([touch.view isKindOfClass:[UIButton class]])
return NO;
return YES;
}