在 iPhone 应用程序中,我们可以隐藏导航栏。默认调用[self.navigationController setNavigationBarHidden:YES animated:YES]
隐藏导航栏会停止屏幕边缘手势识别器 self.navigationController.interactivePopGestureRecognizer
工作,但在过去我可以通过设置其 delegate
来恢复此功能我自己的(当栏被隐藏时)这样做:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return ![otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]];
}
但是,现在该应用程序正在使用UISplitViewController
,这不起作用.
目前尚不清楚分屏 View Controller 是否使用自己的手势识别器或其他问题。我一直无法弄清楚如何让它发挥作用。
我找不到任何其他关于此的讨论。我发现的最新帖子已有多年历史,例如this one , this one ,或this one .
我错过了什么?如何使用屏幕边缘交互式手势 UISplitViewController
导航栏何时隐藏?
最佳答案
谢谢橡皮鸭。 🐥
当然,发布后不久,我就找到了答案:当布局紧凑时,例如在 iPhone 上,UISplitViewController
有一个 UINavigationController
来管理层次结构,此外详细 View Controller 有自己的 UINavigationController
。
因此,解决方案是使用外部导航 Controller (具有多个 View Controller )的 interactivePopGestureRecognizer
,而不是内部导航 Controller (只有一个),因此:
@objc var parentNavigationController: UINavigationController? {
return navigationController?.parent as? UINavigationController
}
我希望这可以帮助遇到此问题的其他人。
关于ios - 使用带有隐藏导航栏的 UISplitViewController 时的屏幕边缘手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66405568/