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