ios - 使用 for 循环添加 subview 在循环结束之前不显示图像

标签 ios swift

我试图添加 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/

相关文章:

ios - 创建 pod,为我的 pod 类使用未声明的类型

ios - 第二次加载 UIView 后 NSConstraints 使应用程序崩溃

ios - 在应用程序更新期间在哪里持久存储用户数据(iOS)?

ios - 在 iOS 上重置 "<App> would like to access your photos"对话框

ios - 如何对 Cocoapods 安装进行 nuke 并从 Github master 开始

ios - 重置整个场景(Swift、SpriteKit)

ios - 找不到 Xcode 7.0 Beta 4 的 GameCenter 框架图像错误

ios - UIView 中的 UIPinchGestureRecognizer 无法正常工作

ios - Sprite Kit中的碰撞检测未检测到碰撞

iphone - 实时 GKMatch 断开连接问题