如何滚动到 UICollectionView 的中心(水平和垂直)
How to scroll to the center of UICollectionView (Both Horizontally and Vertically)
我实现了一个水平和垂直滚动的集合视图(基本上是一个网格)。我想实现在垂直和水平动画选择项目时能够滚动到该项目。
目前我正在使用它作为 "workaround" 但由于显而易见的原因它仍然会跳转。
self.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
self.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: false)
有什么方法可以实现我想要的吗?
UICollectionView.ScrollPosition
是一个 OptionSet
.
你试过了吗
scrollToItem(at: indexPath, at: [.centeredVertically, .centeredHorizontally], animated: false)
?
我实现了一个水平和垂直滚动的集合视图(基本上是一个网格)。我想实现在垂直和水平动画选择项目时能够滚动到该项目。
目前我正在使用它作为 "workaround" 但由于显而易见的原因它仍然会跳转。
self.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
self.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: false)
有什么方法可以实现我想要的吗?
UICollectionView.ScrollPosition
是一个 OptionSet
.
你试过了吗
scrollToItem(at: indexPath, at: [.centeredVertically, .centeredHorizontally], animated: false)
?