手动约束不是 cuasin 展开问题 (swift4)

manual constraints not being cuasin unwrapping issue (swift4)

我下面的代码导致 运行 时间错误。如果我将惰性变量编码为滚动视图,这将起作用。但是,如果我只是想将对象添加到视图或超级视图,这将不起作用。我没有从情节提要中连接任何东西,也不想连接。

   var FIRE: UIImageView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    playSound()





       view.addSubview(FIRE)

    FIRE.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    FIRE.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
    FIRE.widthAnchor.constraint(equalToConstant: 400).isActive = true
    FIRE.heightAnchor.constraint(equalToConstant: 80).isActive = true
    }

改变

var FIRE: UIImageView!

let FIRE = UIImageView()