gpt4 book ai didi

ios - UICollectionView - 滚动到第一个单元格

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

我正在使用 UICollectionView,我需要在单击按钮后滚动到第一个单元格。

该按钮位于我的收藏 View 中的(大)标题部分...单击它时,我需要滚动到位于该按钮下方的第一个单元格。

我创建了这个按钮的 Action ,但我不知道如何滚动到第一个 UICollectionViewCell。

有人可以帮助我吗?

最佳答案

使用此委托(delegate)方法,将 indexPath 设置在第一个位置:

swift

self.collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 0), 
atScrollPosition: .Top,
animated: true)

swift 3

self.collectionView?.scrollToItem(at: IndexPath(row: 0, section: 0), 
at: .top,
animated: true)

objective-C

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] 
atScrollPosition:UICollectionViewScrollPositionTop
animated:YES];

如果您想滚动并停在不同的位置,请更改 UICollectionViewScrollPositionTop

关于ios - UICollectionView - 滚动到第一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32262566/

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