我想在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);
}
}
}
发布于 2017-01-19 21:56:38
如果希望颜色按顺序从一种颜色更改到另一种颜色,则需要提交具有延迟和持续时间值的动画调用,以便在下一个动画开始时完成上一个动画。
假设每个动画的持续时间为1秒。使第一个动画以延迟0开始,第二个动画以延迟1秒开始,依此类推。
(同样适用于其他持续时间。如果持续时间为.3秒,则使每个后续动画的开始时间比前一个动画晚0.3秒。)
https://stackoverflow.com/questions/41752329
复制相似问题