小编Aus*_*tin的帖子

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

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

cocoa swift

6
推荐指数
1
解决办法
604
查看次数

标签 统计

cocoa ×1

swift ×1