我工作的一个开源杂志引擎,你可以看一下在GitHub上:UIGestureRecognizers干扰UIToolbar?
https://github.com/interactivenyc/Defrag
我已经成立了一个UIToolbar在一个UIView我叫MenuPanel。出于某种原因,UIToolbar中的UIBarButtonItems没有正确调用其操作。下面是我使用的按钮语法:
UIBarButtonItem *homeItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];
什么是情况是,无论我点击我的屏幕上,在UITapGestureRecognizer在我的主要UIViewController中宣告被调用来代替。这得到建立在这个代码块在我的主要的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:这里的UIView:UIViewController中的位置:
https://gist.github.com/1431722
而且我MenuPanel
gist.github.com/1431728
欢迎堆栈溢出!请确保将您的答案标记为已接受,以便其他人知道有解决方案。 –