【发布时间】:2015-11-28 04:18:40
【问题描述】:
这是我的情况:
我有一个 tvOS 应用程序,其中基本导航是一个 UITabBarController。从 UITabBarController 引用的每个根视图控制器都是一个 UINavigationController,然后它处理将 ViewControllers 推送到堆栈上。当特定的 ViewController(包含 CollectionView)处于活动状态时,我需要阻止默认的 tvOS UITabBarController 获得焦点的能力。
我尝试在 ViewWillAppear 上手动隐藏 TabBar,将 TabBar 子类化并覆盖首选焦点视图。在大多数情况下,在 TabBar 中取消激活焦点会导致在其 activeViewController 中取消激活焦点。目前我的解决方案是覆盖我的 ViewController 中的“shouldUpdateFocusInContext”委托方法,并防止将焦点放在不是 UICollectionViews 的视图上。这适用于这种情况,但显然是一种次优的黑客解决方案。
override func shouldUpdateFocusInContext(context: UIFocusUpdateContext) -> Bool {
guard let nextFocusView = context.nextFocusedView else {return false}
if nextFocusView.isKindOfClass(UICollectionViewCell.classForCoder()) {
return true
} else {
return false
}
}
关于如何在用户在 tvOS 遥控器上向上滑动时暂时阻止 UITabBarController 的 TabBar 显示,任何人有更好的想法吗?
【问题讨论】: