问题描述
我有两个视图控制器,一个是 GameViewController(这个是在我开始一个新的游戏项目时由 xcode 创建的)和 MenuViewController.最后一个向用户展示了一个按钮开始游戏".按下按钮时,应显示 GameViewController 视图.但是,程序崩溃了,而是在标题中显示消息.
I have two View Controllers, one is GameViewController (this one is created by xcode when I start a new game project) and MenuViewController. This last one presents the user with a button 'start game.' When the button is pressed, the GameViewController view should be presented. However, the program crashes instead with the message in the title.
在MenuViewController"中我有
In 'MenuViewController' I have
func startGameButtonAction(sender:UIButton!) {
let gameViewController = GameViewController()
self.presentViewController(gameViewController, animated: true, completion: nil)
}
在GameViewController"中我有
In 'GameViewController' I have
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
let skView = self.view as! SKView // crash occurs here
}
我需要 skView 是一个 SKView,因为 GameViewController 提供了一个 SKScene.
I need the skView to be an SKView because GameViewController presents an SKScene.
推荐答案
如果你使用storyboard,你可以将View的自定义类设置为SKView,如下所示:
If you user storyboard, you can set View's custom class to SKView, like this:
然后:
这篇关于无法将“UIView"类型的值转换为“SKView"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!