gpt4 book ai didi

ios - 如何在 swift 4 中设置对 collectionView 的关注?

转载 作者:行者123 更新时间:2023-11-29 11:33:27 24 4
gpt4 key购买 nike

你好,我有一个 UICollectionView。在一个特定的单元格中,我有许多 View ,如 UserProfileViewProductViewCommentBoxView 等。在 CommentBoxView 中有一个文本查看用户可以在何处键入然后发表评论。发布评论后,我想关注那个特定的单元格,单元格用户从中发布了评论。为此,我使用了:

func indexPathForPreferredFocusedView(in collectionView: UICollectionView) -> IndexPath? {
return IndexPath(row: 2, section: 0)
}

我正在使用硬编码值进行测试,但它仍然没有出现。请任何人帮助我解决这个问题。

最佳答案

也许您所说的“焦点”是指“滚动到”。如果你想滚动到一个单元格,你应该调用

collectionView.scrollToItem(at: indexPath, scrollPosition: .centeredVertically, animated: true)

查看 documentation 可能会有用对于这个功能。

据我所知,虽然 focus 是 tvOS 开发的核​​心概念,但在 iOS 中,它的主要功能是插入无障碍体验。因此,我认为它不会产生您期望的效果。

关于ios - 如何在 swift 4 中设置对 collectionView 的关注?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51337159/

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