iOS:如何在 swift 3 中选择并滚动到 collectionView 中的特定单元格?

标签 ios swift swift3 uicollectionview uicollectionviewcell

我想选择并滚动到 collectionView 中的特定 indexPath 并将其居中。我发现了这些功能,但无法将它们结合起来:

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

提前致谢。

最佳答案

您可以传递选项集 [.centeredHorizo​​ntally,.centeredVertically]

collectionView.scrollToItem(at: indexPath, at: [.centeredHorizontally,.centeredVertically], animated: true)

关于iOS:如何在 swift 3 中选择并滚动到 collectionView 中的特定单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46079375/

相关文章:

ios - 使用导航 Controller 在滑出面板中显示右键

iphone - 重写 UITextView

swift - FIRApp.Configure 崩溃的应用程序

arrays - Swift - 通过几个比较对数组进行排序

swift - 无法使用类型的参数列表调用 'jsonObject'

swift - DispatchSourceTimer 和 Swift 3.0

ios - 快速单击 UITableView 中的单元格时折叠部分

ios - 构建存折通行证

ios - UITableView 中没有搜索栏的过滤选项

swift - 为什么 Realm 数据库属性值不改变?