【发布时间】:2015-02-02 15:43:04
【问题描述】:
我创建了一个游戏,其中主菜单包含在普通 ViewController 中,而实际游戏在 SKScene 中进行。
我使用主菜单上按钮的模态转场来打开 SKScene。
我遇到的问题是当我尝试从 SKScene 返回主菜单时。
我正在使用此代码来显示主菜单
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if homeBtn.containsPoint(location)
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let settingController: UIViewController = storyboard.instantiateViewControllerWithIdentifier("homeViewController") as UIViewController
let vc = self.view?.window?.rootViewController
vc?.presentViewController(settingController, animated: true, completion: nil)
}
}
}
但是这会导致以下消息:
警告:尝试在其视图不在窗口层次结构中的 ViewController 上呈现 ViewController!
【问题讨论】:
-
你能贴出让你回到“vc”(主菜单)的代码吗?
-
添加了更多代码,希望它更具解释性
标签: ios swift uiviewcontroller sprite-kit