【问题标题】:tvOS - Reset CollectionView's focus at one point of time with remembersLastFocusedIndexPath = true [swift]tvOS - 在一个时间点重置 CollectionView 的焦点, remembersLastFocusedIndexPath = true [swift]
【发布时间】:2021-06-28 15:10:19
【问题描述】:

我设置了一个集合视图,其中 remembersLastFocusedIndexPath 设置为 true。

CollectionView 被设计成具有嵌套的集合视图,

CollectionView 
  -> Section 1
    --->Header
    --->Cell nested with collectionview 
  -> Section 2
    --->Header
    --->Cell nested with collectionview 
....so on....

还有分页。

现在,如果用户滚动到第 7 部分中的第二个项目并单击电视遥控器中的菜单,我会将集合滚动到顶部。 [通过将内容偏移设置为 0 或滚动到第 0 个索引]

要求:滚动到第 0 个索引后,如果用户尝试关注第 0 部分的第一个单元格,我希望焦点位于第 0 个索引处。

问题:但现在集合视图会记住上次聚焦的索引路径并滚动到第 7 节中的第 2 项。

预期:在这种情况下,我不希望集合视图记住最后聚焦的索引路径。在所有其他情况下,应该记住它。即,滚动到顶部后,我想做类似的事情

collectionView.scrollToTop()
resetFocus() //which should reset collection view's focus to initial index.


func resetFocus() { 
//What should be written here to reset the focus of collection view.
}

【问题讨论】:

    标签: ios swift tvos collectionview focus-engine


    【解决方案1】:

    在重设焦点后也尝试实现indexPathForPreferredFocusedView。文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-22
      相关资源
      最近更新 更多