Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSCollectionView performBatchUpdates doesn't animate changes

Tags:

swift

cocoa

When I do the animations individually everything works fine, but inside of a performBatchUpdates block the change is instant, almost like I called reloadData(). Am I using it correctly?

Working method:

NSAnimationContext.currentContext().duration = 0.25

indexPathChanges.map({collectionView.animator().moveItemAtIndexPath($0.0, toIndexPath: $0.1)})

performBatchUpdates version (instant change - no animation):

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)")
like image 579
Austin Avatar asked Apr 26 '16 05:04

Austin


1 Answers

Try to put it this way:

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

In other words, pass it through animator() proxy.

like image 164
Andriy Avatar answered Nov 03 '22 18:11

Andriy