xcode self.navigationController.interactivePopGestureRecognizer.enabled = NO; 不适用于 iOS 8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26098392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
self.navigationController.interactivePopGestureRecognizer.enabled = NO; not working in iOS 8
提问by Dhara
I want to disable the pop gesture on swiping the viewcontroller but the below lines are not working in iOS 8:
我想在滑动视图控制器时禁用弹出手势,但以下几行在 iOS 8 中不起作用:
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
Thanks in Advance
提前致谢
回答by gabbler
In the viewcontroller that you want it to be disabled, add the following line:
在要禁用它的视图控制器中,添加以下行:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return NO;
}
回答by Userich
I use this solution in my project, it disables only interactivePopGestureRecognizer and allows you to use another gesture recognizers.
我在我的项目中使用了这个解决方案,它只禁用了 InteractivePopGestureRecognizer 并允许您使用另一个手势识别器。
- (void)viewDidLoad {
[super viewDidLoad];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isEqual:self.navigationController.interactivePopGestureRecognizer]) {
return NO;
} else {
return YES;
}
}
回答by Bruno
Following solution!!!
以下解决方案!!!
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
__weak id weakSelf = self;
self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf; }
The navigation controller installs this gesture recognizer on its view and uses it to pop the topmost view controller off the navigation stack. You can use this property to retrieve the gesture recognizer and tie it to the behavior of other gesture recognizers in your user interface. When tying your gesture recognizers together, make sure they recognize their gestures simultaneously to ensure that your gesture recognizers are given a chance to handle the event.
导航控制器在其视图上安装这个手势识别器,并使用它从导航堆栈中弹出最顶层的视图控制器。您可以使用此属性来检索手势识别器并将其与用户界面中其他手势识别器的行为联系起来。将您的手势识别器连接在一起时,请确保它们同时识别它们的手势,以确保您的手势识别器有机会处理事件。
Usually we need to implement when you manually add a Navigation Bar or when we customized Navigation Controller
通常我们需要在手动添加Navigation Bar或者自定义Navigation Controller时实现
Swift Version
迅捷版
Add on RootViewController the protocol UIGestureRecognizerDelegate and viewWillAppear add:
在 RootViewController 上添加协议 UIGestureRecognizerDelegate 和 viewWillAppear 添加:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.interactivePopGestureRecognizer!.delegate = self }
回答by xu tong
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
});
}
I think the easy way is above. You should not make gesture enable directly in viewDidLoad()。 But you can change it's state afterviewDidAppeared(). You know it's After, :-D
我认为简单的方法在上面。您不应该直接在 viewDidLoad() 中启用手势。 但是您可以在viewDidAppeared()之后更改它的状态。你知道这是之后,:-D