gpt4 book ai didi

swift2 - UICollectionView : Programmatically moving focus from one view to another - tvOS

转载 作者:行者123 更新时间:2023-12-04 15:25:01 24 4
gpt4 key购买 nike

我正在尝试以编程方式将焦点从一个 View 移动到另一个 View ,就像单击按钮一样 我正在尝试在 Collection View 中选择一个索引。

我正在尝试复制 SIRI 的工作功能,因为 Siri 不对开发人员开放,但我正在将要通过 bonjour 播放的节目发送到应用程序,以便它播放它唯一的一点是节目,即索引路径应该是在播放视频之前集中注意力,就像 NBC 应用程序在 tvOS 中所做的那样。

我试过:

- collectionView.selectItemAtIndexPath(selectedIndexPath, animated: false, scrollPosition: .None)
collectionView.reloadData()
setNeedsFocusUpdate()
collectionView.updateFocusIfNeeded()

似乎没有任何效果并将焦点转移到给定的索引,我想知道这在 tvOS 中是否可行?

我正在构建一个 tvOS 原生应用程序。

最佳答案

根据 App Programming Guide for tvOS,没有明确的方法以编程方式将焦点从一个 View 移动到另一个 View :

The Focus Engine Controls Focus

Only the focus engine can explicitly update focus, meaning there is no API for directly setting the focused view or moving focus in a certain direction. ...

The focus engine controls focus to make sure that it does not move around the screen unexpectedly, and that it behaves similarly across different applications.

但是,您可以拥有 UICollectionViewDelegate为 Collection View 的首选焦点项指定索引路径,当 Collection View 获得焦点时,它将聚焦该索引路径:

func indexPathForPreferredFocusedViewInCollectionView(_ collectionView: UICollectionView) -> NSIndexPath? {
// Return index path for selected show that you will be playing
return NSIndexPath(forRow: ..., inSection: ...)
}

The functionality of this delegate method is equivalent to overriding the UICollectionView class’s preferredFocusedView method in the UIFocusEnvironment protocol. If the collection view’s remembersLastFocusedIndexPath method is set to YES, this method defines the index path that gets focused when the collection view is focused for the first time.

关于swift2 - UICollectionView : Programmatically moving focus from one view to another - tvOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34598023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com