我在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上以分步模式运行时,它不会崩溃。
有什么问题
最佳答案
如果我将代码放在Sources文件夹中,效果很好。似乎是Swift Swiftgrounds的错误。