NSCollectionView performBatchUpdates不会对更改进行动画处理

时间:2016-04-26 05:33:28

标签: swift cocoa

当我单独制作动画时,一切正常,但在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)")

1 个答案:

答案 0 :(得分:6)

试着这样说:

collectionView.animator().performBatchUpdates({<your animations>}, completion handler:{finished in <your completion handler>})

换句话说,将其传递给animator()代理。