添加UITapGestureRecognizer后,UIButtons将无法工作

时间:2012-04-21 16:02:43

标签: objective-c ios xcode uitapgesturerecognizer

我有以下代码,我将UITapGestureRecognizer添加到我的视图中:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                      action:@selector(userTapped)];

 [self.view addGestureRecognizer:tap];

我的问题是,当我按下与UIButton在同一视图上的其他UITapGestureRecognizer(按钮在IB中创建)时,没有任何反应。

我想我只在一个动作(userTapped :)中添加了一个动作(userTapped :),但是如何添加与创建的其他按钮的交互?

1 个答案:

答案 0 :(得分:6)

尝试

tap.cancelsTouchesInView = NO;

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
        if([touch.view isKindOfClass:[UIButton class]])
            return NO;
        return YES;
}