2016-08-01 46 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