当我单独制作动画时,一切正常,但在performBatchUpdates
块内,变化是即时的,几乎就像我调用reloadData()
一样。我正确使用它吗?
工作方法:
NSAnimationContext.currentContext().duration = 0.25
indexPathChanges.map({collectionView.animator().moveItemAtIndexPath($0.0, toIndexPath: $0.1)})
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)")
答案 0 :(得分:6)
试着这样说:
collectionView.animator().performBatchUpdates({<your animations>}, completion handler:{finished in <your completion handler>})
换句话说,将其传递给animator()
代理。