私のアプリは、tableView
バッチ更新によって更新される を使用しています。
セルにはindicatorImage
、テーブルのセクションに依存する があります。セルがセクション間を移動すると、このインジケーターが変化するので、インジケーター画像の変化をアニメーション化したいと考えています。
そのために、first を使用しtableView.performBatchUpdates
て、セルの削除、挿入、および移動をアニメーション化します。
次に、バッチ更新をCATransaction
ブロックに埋め込んで、画像の変化をアニメーション化します。
これは 1 つの例外を除いて完全に機能します。テーブル ビューの更新中にアラートを表示する必要がある場合、アプリは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: 私はこの質問を読みましたが、回答がありません。対照的に、myUIWindow
は定義されています。