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

Ωlo*_*stA 4 ios uicollectionview uicollectionviewcell swift swift3

我想选择并滚动到一个特定indexPathcollectionView中心.我找到了这些功能,但不可能将它们组合起来:

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)
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Igo*_*ets 7

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

collectionView.scrollToItem(at: indexPath, at: [.centeredHorizontally,.centeredVertically], animated: true)
Run Code Online (Sandbox Code Playgroud)