本文介绍了UICollectionView - 滚动到下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有机会使用UICollectionView滚动到所需项目。 scrollToItemAtIndexPath并且不捕捉项目本身,而是捕捉到项目所属的页面? (我启用了分页功能。)

Is there any chance to scroll in the UICollectionView to the wanted item using . scrollToItemAtIndexPath and snap not to the item itself, but to the page the item is part of? (I got paging enabled.)

干杯

推荐答案

你需要创建 NSIndexPath 而不是滚动到该索引。

You need to create NSIndexPath than scroll to that index.

 //Mark: - Move to cell when view did appear

overload viewDidAppear() {


    let scrollIndex: NSIndexPath = NSIndexPath(forItem: dayIndex, inSection: monthSection)
    if (// Check you are in range of UIcollectionView's count) {
        //Scroll collectionview according to your requirement i.e UICollectionViewScrollPositionCenteredHorizontally or UICollectionViewScrollPosition.Left
        self.YourCollectionView.scrollToItemAtIndexPath(scrollIndex, atScrollPosition: UICollectionViewScrollPositionCenteredHorizontally, animated: true)
    }
}

这篇关于UICollectionView - 滚动到下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:47