【发布时间】:2019-02-15 14:56:31
【问题描述】:
中午好
我需要向一个方向滚动 uicollection 视图单元格。
例如:-
我有 4 个数据值的数组 -> ["apple","pen","book","bottle"]。
我需要像这样滚动 Uicollectionview 单元格:
苹果 -> 笔 -> 书 -> 瓶子 -> 苹果 -> 笔 -> 书 -> 瓶子 -> 继续..
我将此代码用于自动滚动,但在我的情况下,集合视图滚动如下:
苹果 -> 笔 -> 书 -> 瓶子 笔 -> 书 -> 瓶子
代码:
@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)
}
}
}
}
提前致谢。
【问题讨论】:
-
我认为你需要循环集合视图这里是链接raywenderlich.com/…
标签: ios swift xcode swift3 uicollectionview