此代码驻留在viewDidLoad函数中。第一次被称为它是好的。但是后来我从同一个故事板文件中提出了一个子视图,当时让skView = gameView为! SKView'再次被调用并抛出致命错误:发现无...我如何阻止它被其他时间调用?我无法想到我能做到的任何检查。
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = gameView as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
答案 0 :(得分:0)
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
let skView = self.view as! SKView
if skView.scene == nil {
if let scene = GameScene(fileNamed:"GameScene") {
skView.presentScene(scene)
}
}
}