【发布时间】:2017-01-19 21:48:30
【问题描述】:
我想在 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);
}
}
}
【问题讨论】:
-
self.container?.viewWithTag(v/j)可能为零 -
哪一部分不行?
-
所以您将视图背景颜色随机更改为白色?