我正在尝试制作TableView动画(扩展单元格),然后更改单元格外观(添加阴影)。
它将看起来像这样
但是我发现,如果将阴影与扩展动画设置在同一运行循环中,则阴影会被覆盖:
tableView.beginUpdates()
cell.footerContainer.isHidden = false
tableView.endUpdates()
cell.highlightMode = true //computed property to add top+bottom shadow
但是,如果我添加了一个延迟(大概是在随后的运行循环中),则一切正常:
tableView.beginUpdates()
cell.footerContainer.isHidden = false
tableView.endUpdates()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
cell.highlightMode = true //computed property to add top+bottom shadow
}
但这并不可靠,因为在一台设备上运行0.3可能适用于速度较慢的设备。所以我尝试了这个:
CATransaction.begin()
CATransaction.setCompletionBlock {
cell.highlightMode = true //computed property to add top+bottom shadow
}
tableView.beginUpdates()
cell.footerContainer.isHidden = false
tableView.endUpdates()
CATransaction.commit()
那也不起作用。
有什么更好的方法?