我从 这里得到了相反的问题.iOS7
默认情况下,UINavigationController
堆栈的向后滑动手势可以弹出呈现的ViewController
.现在我只是统一了所有 ViewControllers
的所有 self.navigationItem.leftBarButtonItem
样式.
I got the opposite issue from here.
By default in iOS7
, back swipe gesture of UINavigationController
's stack could pop the presented ViewController
. Now I just uniformed all the self.navigationItem.leftBarButtonItem
style for all the ViewControllers
.
代码如下:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:LOADIMAGE(@"back_button") style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
之后,navigationController.interactivePopGestureRecognizer
被禁用.如何在不删除自定义 leftBarButtonItem
的情况下启用弹出手势?
after that, the navigationController.interactivePopGestureRecognizer
is disabled. How could I make the pop gesture enabled without removing the custom leftBarButtonItem
?
谢谢!
在viewDidLoad中首先设置委托:
First set delegate in viewDidLoad:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
然后在推送时禁用手势:
And then disable gesture when pushing:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
self.interactivePopGestureRecognizer.enabled = NO;
}
并在 viewDidDisappear 中启用:
And enable in viewDidDisappear:
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
另外,将 UINavigationControllerDelegate
添加到您的视图控制器.
Also, add UINavigationControllerDelegate
to your view controller.
这篇关于设置 leftBarButtonItem 后如何在 UINavigationController 中启用后退/左滑手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!