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