繁体   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