【问题标题】:How to scroll to the center of UICollectionView (Both Horizontally and Vertically)如何滚动到 UICollectionView 的中心(水平和垂直)
【发布时间】:2019-03-05 10:04:20
【问题描述】:

我已经实现了一个可以水平和垂直滚动的collectionview(基本上它是一个网格)。我希望能够在垂直和水平动画选择项目时滚动到项目。

目前我将其用作“解决方法”,但由于显而易见的原因,它仍然会跳转。

 self.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
 self.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: false)

有没有办法实现我想要发生的事情?

【问题讨论】:

    标签: ios swift uiscrollview uicollectionview


    【解决方案1】:

    UICollectionView.ScrollPosition 是一个OptionSet

    你试过了吗

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

    ?

    【讨论】:

    • 谢谢!是的,这正是我所需要的。
    猜你喜欢
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2021-11-13
    • 2015-09-27
    相关资源
    最近更新 更多