【发布时间】:2014-12-22 18:24:31
【问题描述】:
我正在尝试在我的游戏中创建暂停屏幕。我在情节提要中添加了一个“PauseScreen”视图控制器,情节提要 ID 和恢复 ID 设置为“PauseScreenID”,并移动到暂停屏幕,我在“GameScene”中创建了该功能:
func pauseSceenTransition(){
let viewController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("PauseScreenID") as UIViewController
let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)
currentViewController.window?.rootViewController?.presentViewController(viewController, animated: false, completion: nil)
}
但是当它被调用时,我得到了错误:
警告:尝试在 AppName.StartScreenViewController: 0x7fae61f79980> 上显示 AppName.PauseScreen: 0x7fae61fe5ff0>,其视图不在窗口层次结构中!
“StartScreenViewController”是我的开始屏幕的视图控制器,也是初始视图控制器。然后它转到“GameScene”,这是“PauseScreen”需要去的地方。如果我将初始视图控制器设为“GameViewController”/“GameScene”,它会起作用,所以我认为我需要更改第二行:
let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)
所以它在“GameViewController”上显示“PauseScreen”,而不是在“StartScreenViewController”上,但我不知道该怎么做。
【问题讨论】:
标签: swift xcode6 viewcontroller presentviewcontroller