当我在导航栏上从左向右滑动时,我的导航控制器会弹出一个视图控制器。我已经看过this question所以我知道我可以设置......
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
...但它只是禁用导航栏下方视图的滑动,而不是栏本身。
我目前的解决方案是手动查找手势并禁用它。哪个有效,但不确定是否有更好的方法。导航栏似乎没有interactivePopGestureRecognizer
等属性。
// This is inside a `UINavigationController` subclass.
for (UISwipeGestureRecognizer *gr in self.navigationBar.gestureRecognizers) {
if ([gr isKindOfClass:[UISwipeGestureRecognizer class]] && gr.direction == UISwipeGestureRecognizerDirectionRight) {
gr.enabled = NO;
}
}
答案 0 :(得分:3)
UIGestureRecognizerDelegate
有一个名为- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
的方法。
如果您能够指出触摸的视图是UINavigationBar
,只需返回“否”。
喜欢
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return (![[[touch view] class] isSubclassOfClass:[UIControl class]]); // UIControl is whatever as you like.
}