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

标签 swift cocoa

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

相关文章:

objective-c - didConnectToHost 没有被调用

objective-c - NSScrollView 内的 NSTextView 不滚动 :(

cocoa - NSTableView 适用于 osx 10.0,但 NsTableViewDataSource 仅适用于 10.6?

ios - swift 属性的未知类型名称

ios - NavigationItem 中的 titleView 不考虑 iOS 11 中的框架高度

ios - 打开并编辑Swift 3.0插件SDK

ios - 在一个 tableView 上同时获取 2 个 URLRequests

ios - 将数据上传到模拟的 iOS 设备

cocoa - 求和 UIView subview 属性的 KVC 路径是什么?

objective-c - 通过标题获取 NSMenu 树的 NSMenuItem