中午好
我需要在一个方向上滚动uicollection视图单元格。
例如:
我有一个包含4个数据值的数组 -> ["apple","pen","book","bottle"]。
我需要像这样滚动Uicollectionview单元格:
apple -> pen -> book -> bottle -> apple -> pen -> book -> bottle -> 继续...
我使用了这段代码来自动滚动,但是在我的情况下,集合视图会像这样滚动:
apple -> pen -> book -> bottle <- (向后滚动到第一个索引) apple -> pen -> book -> bottle
代码:
@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)
}
}
}
}
提前感谢。