我试图添加 subview ,但所有添加的 subview 仅在 for 循环结束时显示,我想知道是否有办法让每个 subview 在已添加时显示,这是我的代码
for colum in 0 ... colums-1 {
xPos = colum * seatWidth
for row in 0 ... rows-1 {
yPos = row * seatWidth
let seatImageView = dataSource?.seatsView(sender: self, seatImageViewForRow: row, andColum: colum)
if seatImageView?.state != .empty {
seatImageView?.delegate = self
seatImageView!.frame = CGRect(x: xPos, y: yPos, width: seatWidth, height: seatWidth)
containerView?.addSubview(seatImageView!)
}
}
xPos = 0
}
最佳答案
如果在添加 View 后直接添加Runloop.main.run(until: Date.distantPast)
。 UI 直到下一个运行循环才会正常更新,添加这段代码将确保它运行一次,所以它被更新了。
关于ios - 使用 for 循环添加 subview 在循环结束之前不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41191285/