ios - UIGestureRecognizers 干扰 UIToolbar?

标签 ios open-source

我正在开发一个开源杂志引擎,您可以在 GitHub 上查看它:

https://github.com/interactivenyc/Defrag

我已经在我称为 MenuPanel 的 UIView 中设置了一个 UIToolbar。出于某种原因,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 忽略来自任何 UIToolbar 的触摸:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    //ignore any touches from a UIToolbar

    if ([touch.view.superview isKindOfClass:[UIToolbar class]]) {
        return NO;
    }

    return YES;
}

关于ios - UIGestureRecognizers 干扰 UIToolbar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8379682/

相关文章:

ios - 将设备方向设置为仅适用于 iPad 的横向

java - 开源文档管理系统

algorithm - 内容检测算法

ios - UIButton 随中心改变大小

ios - Swift 和 EXT_BAD_ACCESS 中的详细文本标签

ios - dataWithContentsOfFile 返回空

ruby-on-rails - 如果即使对于开源项目,rails 项目的任何源代码也应该被隐藏怎么办?

delphi - 有没有用 Delphi 制作的开源文字处理器?

c# - WPF 功能区控件

ios - AppsFlyer Onelink 深度链接调试