我的应用程序使用
tableView
通过批量更新进行更新。
这些细胞有一个
indicatorImage
这取决于桌子的部分。
当一个单元格在各个部分之间移动时,这个指示器会发生变化,我想为指示器图像的变化设置动画。
为此,我首先使用
tableView.performBatchUpdates
为细胞的删除、插入和移动设置动画。
其次,我将批量更新嵌入到
CATransaction
块以设置图像更改的动画。
除了一个例外,这一点非常有效:
如果在表格视图更新期间显示警报,我的应用程序将在
UITableViewAlertForLayoutOutsideViewHierarchy
断点。
以下是代码:
CATransaction.begin()
tableView.performBatchUpdates({
tableView.deleteRows(at: deletions, with: .automatic)
tableView.insertRows(at: insertions, with: .automatic)
for (from, to) in movements {
tableView.moveRow(at: from, to: to)
if from.section == kTableSectionBought {
if let cell = tableView.cellForRow(at: from) {
let indicatorImage = to.section < 2 ? self.progressImages!.first : self.progressImages!.last
UIView.transition(with: cell.imageView!, // see <https://stackoverflow.com/a/40472115/1987726>
duration: 0.25,
options: .transitionCrossDissolve,
animations: { cell.imageView!.image = indicatorImage },
completion: nil)
}
}
}
animateCells(deletions: deletions, movements: movements)
}, completion: { (finished) in
// some code
}
我的问题是:
问题的原因可能是什么?我该如何避免?
附言:我读过
this question
,但它没有答案,相反,我的
UIWindow
定义了。