ios - 如何禁用 tvOS Apple TV 中的自动焦点更改
问题描述
我有一个带有 collectionView 的详细信息页面。集合视图有一个标题视图,其中有一些按钮(播放按钮)。当页面第一次打开时,焦点将放在播放按钮上。加载标题视图后,我们将插入轨道单元格以在 collectionView 中显示相关项目。但是,每当轨道加载时,焦点就会自动移动到轨道单元。没有为collectionView做焦点处理只有一个是这段代码
func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
return true
}
我怎样才能消除这种行为?我尝试“应该更新焦点”来获得这个焦点变化并阻止它
override func shouldUpdateFocus(in context: UIFocusUpdateContext) -> Bool {
<#code#>
}
但是只有当焦点更改是通过远程进行并且没有自动焦点更改(例如我的情况)时才会触发此功能现在我正在处理这种情况
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if let headerView = getHeaderView(), let collectionViewCell = detailsCollectionView.cellForItem(at: IndexPath(item: 0, section: 0)) as? CollectionViewCell {
let previouslyFocusedView = context.previouslyFocusedView
let nextFocusedView = context.nextFocusedView
if previouslyFocusedView?.isDescendant(of: headerView.playButton) ?? false, nextFocusedView?.isDescendant(of: collectionViewCell.getInnerCollectionView()) ?? false {
cancelFocusChange(previouslyFocusedView: previouslyFocusedView)
}
}
super.didUpdateFocus(in: context, with: coordinator)
}
但我认为这不是一个好主意。发生这种焦点变化一定是有原因的。如果有人知道这个问题的答案,请帮忙。
解决方案
推荐阅读
- python - 如何导入“进程”包?
- mongodb - MongoDB中的类别层次结构
- javascript - 在 Express 应用程序中托管 Gatsby 博客
- scala - 基于具有交集的外部数组过滤数据帧数组项
- java - 浏览器是否将 PAGE-REQUEST 作为所有页面请求的“GET”http 方法发送?
- excel - excel vba 只有注释可能出现在 end sub 之后
- javascript - 如何在 angularjs 中通过 npm 安装 angular-ui-bootstrap?
- tomcat - 如何找到单个tomcat服务器下的实例和活动实例的总数?
- c# - VS For Mac 错误生成 android 构建 - NDK
- php - Laravel Telescope 无法进行全新安装(路径错误)