0
無限的網頁,我玩上Git的發現驚人的項目:https://github.com/ink-spot/UPCarouselFlowLayout斯威夫特:在UiCollectionView
我想創建一個無限旋轉木馬。這意味着它將從最後一個之後的第一個項目開始。
我試圖修改的CollectionView - cellForItemAtIndexPath方法的代碼:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(CarouselCollectionViewCell.identifier, forIndexPath: indexPath) as! CarouselCollectionViewCell
let character = items[indexPath.row]
cell.image.image = UIImage(named: character.imageName)
if indexPath.row == items.count - 2 {
items.insert(items[0], atIndex: items.count)
items.removeAtIndex(0)
//self.collectionView.reloadItemsAtIndexPaths([NSIndexPath(forItem: 0, inSection: 0)])
self.collectionView.reloadData()
}
return cell
}
我的想法是更新源陣列的第一元素移動到該端部。但它不起作用。
另外我有一個問題,我怎樣才能修改代碼,以查看程序加載後中心的第二個元素?所以它會顯示第二個元素,並且將在左邊第一個和第三個在右邊。
謝謝!
是的,它使用UICollectionView和你的鏈接不會幫助,因爲它需要單元格填充集合視圖框架的全部寬度。在我的例子中,一個元素在中心,兩個從左到右 – Almazini