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

iOS: How to select and scroll to a specific cell in a collectionView in swift 3?

我想 select 并滚动到 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)

提前致谢。

你可以传递选项集[.centeredHorizontally,.centeredVertically]

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