jjzjj

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

coder 2023-09-04 原文

当我单独制作动画时,一切正常,但在 performBatchUpdates block 内部,更改是即时的,几乎就像我调用 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)")

最佳答案

试着这样说:

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

换句话说,通过 animator() 代理传递它。

关于swift - NSCollectionView performBatchUpdates 不会对更改进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36856027/

有关swift - NSCollectionView performBatchUpdates 不会对更改进行动画处理的更多相关文章

随机推荐