【发布时间】:2018-10-10 17:52:31
【问题描述】:
我有一个用于 iPad 的数学程序,它使用一个 Big Number 库进行计算,然后根据这些计算更新 UIView (myView) 中最多 20,000 个 UILabel 的数组。
计算可能需要大约 5 秒,在此期间每个 UILabel 的 backgroundColor 都设置为一种颜色。因为屏幕上什么都没有发生,所以我有一个闪烁的 UILabel inProgressLabel 通知用户系统正在计算。然后我调用 layoutIfNeeded,想法是当它完成时,屏幕将被更新。最后,我关闭了闪烁的 UILabel。
伪代码如下:
inProgressLabel.turnOnBlinking()
for row in 0..<rowCount
{
for col in 0..<colCount
{
// perform some calculation
let z = buttonArray[row][col].performCalculation()
//now set the Label background based on the result of the calculation
buttonArray[row][col].setLabelBackground(z)
}
}
myView.layoutIfNeeded()
inProgressLabel.turnOffBlinking()
我的理解是 layoutIfNeeded() 是同步的。因此,屏幕将更新,然后,只有这样,闪烁的 inProgressLabel 才会关闭。但是,inProgressLabel 实际上在 layoutIfNeeded 调用后立即关闭,然后可能需要 5 秒钟才能更新 UILabel 数组。
我认为这可能是因为更新发生在不同的线程中。如果是这样,有没有办法确定 UIView 和 UILabel 数组何时完成更新(显示),以便我可以关闭闪烁的 UILabel?
提前非常感谢。
【问题讨论】: