用户界面识别器干扰用户工具栏



我正在做一个开源杂志引擎,你可以在GitHub上看看:

https://github.com/interactivenyc/Defrag

我在UIView中设置了一个工具栏,我叫它MenuPanel。由于某些原因,UIToolbar中的UIBarButtonItems没有正确调用它们的动作。以下是我对按钮使用的语法:

UIBarButtonItem *homeItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];

发生的是我在屏幕上点击的任何地方,在我的主UIViewController中声明的UITapGestureRecognizer被调用了。这是在我的主UIViewController中的这段代码中设置的:

- (void)setupGestureRecognizers {
//NSLog(@"setupGestureRecognizer NEW");
UISwipeGestureRecognizer *swipeRecognizer;
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
UITapGestureRecognizer *tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.view addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}

我敢肯定,我在如何做到这一点上有一些非常基本的概念错误。有人能告诉我如何解决这个问题吗?

作为参考,你可以看到我的主DefragViewController: UIViewController在这里:

https://gist.github.com/1431722

我的MenuPanel: UIView这里:

gist.github.com/1431728

我自己解决了问题。

我必须告诉我的UIViewController忽略来自任何ui工具栏的触摸,像这样:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    //ignore any touches from a UIToolbar
    if ([touch.view.superview isKindOfClass:[UIToolbar class]]) {
        return NO;
    }
    return YES;
}

最新更新