如何在一个方向上快速滚动UICollectionview?

问题描述 投票:5回答:2

中午

我需要在一个方向上滚动uicollection视图单元。

例如:-

我有一个具有4个数据值的数组-> [“ apple”,“ pen”,“ book”,“ bottle”]。

我需要像这样滚动Uicollectionview单元:

苹果->笔->书->瓶子->苹果->笔->书->瓶子->继续。]]

我使用此代码进行自动滚动,但在我的情况下,集合视图滚动如下:

苹果->笔->书->瓶子笔->书->瓶子

code:

@objc func scrollAutomatically(_ timer1: Timer) {

      if let coll  = CV_Slider {
            for cell in coll.visibleCells {
                let indexPath: IndexPath? = coll.indexPath(for: cell)
                if ((indexPath?.row)!  < self.arr_img_Slide.count - 1){
                    let indexPath1: IndexPath?
                    indexPath1 = IndexPath.init(row: (indexPath?.row)! + 1, section: (indexPath?.section)!)

                    coll.scrollToItem(at: indexPath1!, at: .centeredHorizontally, animated: true)
                }
                else{
                    let indexPath1: IndexPath?
                    indexPath1 = IndexPath.init(row: 0, section: (indexPath?.section)!)
                    coll.scrollToItem(at: indexPath1!, at: .centeredHorizontally, animated: true)
                }

            }
        }
    }

提前感谢。

中午,我需要在一个方向上滚动uicollection视图单元格。例如:-我有4个数据值的数组-> [“ apple”,“ pen”,“ book”,“ bottle”]。我需要滚动Uicollectionview单元格,如...

ios swift xcode swift3 uicollectionview
2个回答
1
投票

1)从'collectionView:numberOfItemsInSection:'返回一些非常大的数字,例如NSIntegerMax


0
投票

如果只想在右侧滚动,则可以执行以下操作:

© www.soinside.com 2019 - 2024. All rights reserved.