当我单独制作动画时,一切都运行正常,但在一个performBatchUpdates
区块内,变化是即时的,就像我打电话一样reloadData()
.我正确使用它吗?
工作方式:
NSAnimationContext.currentContext().duration = 0.25
indexPathChanges.map({collectionView.animator().moveItemAtIndexPath($0.0, toIndexPath: $0.1)})
Run Code Online (Sandbox Code Playgroud)
performBatchUpdates
版本(即时更改 - 无动画):
NSAnimationContext.currentContext().duration = 0.25
collectionView.performBatchUpdates( {
indexPathChanges.map({self.collectionView.moveItemAtIndexPath($0.0, toIndexPath: $0.1)})
// tried this as well - no luck
// indexPathChanges.map({self.collectionView.animator().moveItemAtIndexPath($0.0, toIndexPath: $0.1)})
}, completionHandler: {(finished) in print("Finished: \(finished)")
Run Code Online (Sandbox Code Playgroud)