gpt4 book ai didi

swift - UICollectionView 水平滚动静态焦点项目

转载 作者:行者123 更新时间:2023-11-28 07:45:53 25 4
gpt4 key购买 nike

我正在尝试创建一个嵌入在 tvOS 上的 UITableViewCell 中的可水平滚动的 UICollectionView,并且已经实现了我的目标。

接下来我需要做的是能够将焦点转移到 UICollectionView 中的下一个项目,但是整个项目堆栈应该向左或向右移动一个位置,但焦点将保持在视觉上的“第一个”项目。

这是我希望实现的 ASCII 小图:

Scenario 1, before focus shifts
---------------------
1. | v v v v v |
2. |[v] v v v v |
3. | v v v v v |
---------------------

Scenario 1, after focus shifts
---------------------
1. | v v v v v |
2. | v [v] v v v |
3. | v v v v v |
---------------------

上面的场景 1 是默认行为,焦点转移到 UICollectionView 中的下一个项目。

Scenario 2, before focus shifts
---------------------
1. | v v v v v |
2. |[v] v v v v |
3. | v v v v v |
---------------------

Scenario 2, after focus shifts
---------------------
1. | v v v v v |
2. v |[v] v v v |
3. | v v v v v |
---------------------

场景 2 中,我在 Remote 上滑动以选择 UICollectionView 中的下一个项目后,焦点应保持在左侧,但焦点下方的项目应移动一个。

有没有人对如何实现这一目标有任何提示?

我读过有关 UICollectionView 中粘性列的帖子,但我认为这不完全是粘性列?

最佳答案

我最近不得不为一个项目做这件事。这是我使用的:

 override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if let focusView = context.nextFocusedView as? UICollectionViewCell, let indexPath = collection.indexPath(for: focusView) {

collection.isScrollEnabled = false
coordinator.addCoordinatedAnimations({
self.collection.scrollToItem(at: indexPath, at: .left, animated: true)
}, completion: nil)
}
}

关于swift - UICollectionView 水平滚动静态焦点项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51075017/

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