簡體   English   中英

如何使用Swift為UICollectionView插入動畫?

[英]How do I animate UICollectionView insert with Swift?

我已經用collectionView.reloadData()嘗試過了,但是實際上並沒有解決。 我該怎么辦?

如果您的collectionview只有一個部分,請嘗試:

self.collectionView.performBatchUpdates({
                let indexSet = IndexSet(integersIn: 0...0)
                self.collectionView.reloadSections(indexSet)
            }, completion: nil)

如上所示: https : //stackoverflow.com/a/42001389/4455570

reloadData不會更改布局或設置動畫。 您必須更改項目的位置,例如:

func shuffleTwoCells(srcIndex index1: Int, destIndex index2: Int) {
    let firstIndexPath  = IndexPath(row: Int(index1), section: 0)
    let secondIndexPath = IndexPath(row: Int(index2), section: 0)
    self.collectionView?.moveItem(at: firstIndexPath, to: secondIndexPath)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM