ios - 使用带有隐藏导航栏的 UISplitViewController 时的屏幕边缘手势

标签 ios uinavigationcontroller uisplitviewcontroller

在 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/

相关文章:

ios - Xcode - 在我的应用程序上启用 iTunes 文件共享,但它没有出现在 iTunes 的列表中?

android - Sinch - Android 和 iOS 中的群发消息

ios - Cocos2D & ccDrawLine - 绘制流畅的线条

ios - 带有 NavigationBar 的 TabBarController

ios - UISplitViewController 扩展给应用带来了麻烦

ios - 为加载的 .xib 分配属性

swift - 使用 Swift 呈现下一个 ViewController 以关闭当前 ViewController

iOS Navigation Controller/Storyboard Segues 主要优势?

ios - UISplitViewController Detail View 旋转后消失

objective-c - 启动应用后模态视图不出现