2016-08-01 44 views
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 
} 

我的想法是更新源阵列的第一元素移动到该端部。但它不起作用。

另外我有一个问题,我怎样才能修改代码,以查看程序加载后中心的第二个元素?所以它会显示第二个元素,并且将在左边第一个和第三个在右边。

谢谢!

回答

0

您可以在github上使用this (SwipeView)库。我也用在我的项目中。为无限滚动视图设置以下属性。

self.swipeView.wrapEnabled = true 

它很容易使用。试试你的自我。

如果你的界面使用UICollectionView如果可能想访问本教程here。这解释了如何使用UICollectionView实现无限滚动。

+0

是的,它使用UICollectionView和你的链接不会帮助,因为它需要单元格填充集合视图框架的全部宽度。在我的例子中,一个元素在中心,两个从左到右 – Almazini