我想在 while 循环中更改 UIView
的颜色。我正在从主线程调用 start()
。
示例:
func start() {
let item = Percolation(n: self.tileSideCount)
while (!item.percolates()) {
let v = Int(arc4random_uniform(UInt32(self.tileSideCount))) + 1
let j = Int(arc4random_uniform(UInt32(self.tileSideCount))) + 1
UIView.animate(withDuration: 0.3, delay: 0.0, options: [], animations: {
self.container?.viewWithTag(v)?.backgroundColor = UIColor.white
self.container?.viewWithTag(j)?.backgroundColor = UIColor.white
}, completion: { (finished: Bool) in
})
if (!item.isOpen(i: v, j: j)) {
item.open(i: v, j: j);
}
}
}
最佳答案
如果您希望颜色按顺序从一种变为下一种,您需要提交带有延迟和持续时间值的动画调用,以便前一个动画在下一个动画开始时完成。
假设每个动画的持续时间为 1 秒。使第一个动画以 0 延迟开始,第二个动画以 1 秒延迟开始,等等。
(这同样适用于其他持续时间。如果您的持续时间是 0.3 秒,则让每个后续动画比前一个动画晚 0.3 秒开始。)
关于ios - 在 while 循环中更新 UIView 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41752329/