只是想让我的 navigationController 的 navigationBar 可点击。它适用于
UITapGestureRecognizer* tapRecon = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(toggleMenu)];
tapRecon.delegate = self;
tapRecon.numberOfTapsRequired = 1;
[self.navigationBar addGestureRecognizer:tapRecon];
但是当我有一个后退按钮时,无法点击它(手势可能会接管按钮)。
所以,我尝试了一些在这里找到的东西:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return (![[[touch view] class] isSubclassOfClass:[UIButton class]]);
}
什么都没有,因为[touch view]
总是 UINavigationBar ...
我尝试做的最后一件事是cancelsTouchesInView
将NO
. 没关系,我们可以点击返回按钮,但是还是调用了的toggleMenu
动作。UITapGestureRecognizer
您是否有让后退按钮再次起作用但不同时调用的想法toggleMenu
?
谢谢 !
编辑 :
Juste找到了怎么做:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
for (UIView* sub in self.navigationBar.subviews) {
NSString *cl = NSStringFromClass([sub class]);
if ([cl isEqualToString:@"UINavigationItemButtonView"]) {
CGRect bback = sub.frame;
CGPoint pointInView = [touch locationInView:gestureRecognizer.view];
return !CGRectContainsPoint(bback, pointInView);
}
}
return YES;
}