以不同速度运行时,Swift Playgrounds崩溃

时间:2019-03-22 04:41:43

标签: ios swift uikit swift-playground

我在viewDidAppear中有此代码

    override func viewDidAppear(_ animated: Bool) { 
        BGAmbient.frame = CGRect(x: 0, y: 0, width: arView.center.x*2, height: arView.center.y*2)
        BGAmbient.backgroundColor = UIColor(red: BGred, green: BGgreen, blue: BGblue, alpha: BGalpha)
        arView.addSubview(BGAmbient)
     
        let imageName = "Title.png"
        let image = UIImage(named: imageName)
        let imageView = UIImageView(image: image!)
        var locX: CGFloat = 0
        var locY: CGFloat = 0
        var x: CGFloat = 0.7
        var y:CGFloat = 0.4
        x = arView.center.x - arView.center.x * x
        y = arView.center.y - arView.center.y * y
        var w = arView.center.x * CGFloat(2) * 0.7
        var h = arView.center.y * CGFloat(2) * 0.4
        imageView.frame = CGRect(x: x,
                                 y: y,
                                 width: w, height: h)

  }

我现在正在迅速的操场上的iPad上运行它。但是,它总是在arView.addSubView(BGAmbient)上崩溃或让imageView = UIImageView(image: image!)崩溃。

但是,在Xcode上运行或在iPad上逐步运行时,它不会崩溃。 有什么问题吗?

1 个答案:

答案 0 :(得分:0)

如果我将代码放在Sources文件夹中,效果很好。好像是Swift Playgrounds的错误。