gpt4 book ai didi

ios - 如何快速滚动到collectionview中的特定索引

转载 作者:IT王子 更新时间:2023-10-29 05:25:04 27 4
gpt4 key购买 nike

我们有一个 Collection View 。我制作了一个水平显示日期的日历,我水平滚动日期。现在在屏幕上我只看到 3-4 个日期。现在我想在显示日历屏幕时自动滚动到特定的选定日期。所以我想滚动到的日期尚不可见。

为此,我得到了特定单元格的索引路径。现在我试图将它滚动到特定的索引路径。

  func scrollCollectionView(indexpath:IndexPath)
{
// collectionView.scrollToItem(at: indexpath, at: .left, animated: true)
//collectionView.selectItem(at: indexpath, animated: true, scrollPosition: .left)
collectionView.scrollToItem(at: indexpath, at: .centeredHorizontally, animated: true)
_ = collectionView.dequeueReusableCell(withReuseIdentifier: "DayCell", for: indexpath) as? DayCell

}

请告诉我如何实现它?

最佳答案

在 Controller 的 viewDidLoad 中,您可以编写用于滚动到 Collection View 的特定索引路径的代码。

self.collectionView.scrollToItem(at:IndexPath(item: indexNumber, section: sectionNumber), at: .right, animated: false)

关于ios - 如何快速滚动到collectionview中的特定索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40786699/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com