如何使用Swift设置UICollectionView插入动画?
我已经用collectionView.reloadData()尝试过了,但没有真正起作用。我该怎么办?重新加载数据既不会改变布局也不会设置动画。 您必须更改项目的位置,例如:如何使用Swift设置UICollectionView插入动画?,swift,animation,uicollectionview,Swift,Animation,Uicollectionview,我已经用collectionView.reloadData()尝试过了,但没有真正起作用。我该怎么办?重新加载数据既不会改变布局也不会设置动画。 您必须更改项目的位置,例如: func shuffleTwoCells(srcIndex index1: Int, destIndex index2: Int) { let firstIndexPath = IndexPath(row: Int(index1), section: 0) let secondIndexPath = In
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)
}
如果collectionview只有一个部分,请尝试:
self.collectionView.performBatchUpdates({
let indexSet = IndexSet(integersIn: 0...0)
self.collectionView.reloadSections(indexSet)
}, completion: nil)
如上所示:但这是为了交换两个,而不是插入一个新的,是吗?不知何故,您应该使用方法。由于没有代码片段,即这是一个一般性问题,我建议选中-插入单元格部分-以检查如何使用它。您的注释应该是答案。