我的应用程序使用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
}
我的问题是:
该错误的原因可能是什么,我该如何避免它?
PS:我已经阅读了这个问题,但它没有答案,相反,我UIWindow
的被定义了。