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.PauseScreen:0x7fae61fe5ff0> on< AppName.StartScreenViewController:0x7fae61f79980>其视图不在窗口层次结构中!
“StartScreenViewController”是我的开始屏幕的视图控制器,是初始视图控制器.然后转到“GameScene”,这是“PauseScreen”需要去的地方.如果我将初始视图控制器设置为“GameViewController”/“GameScene”,它可以工作,所以我认为我需要更改第二行:
let currentViewController = (UIApplication.sharedApplication().delegate as AppDelegate)
所以它在“GameViewController”上呈现“PauseScreen”,而不是“StartScreenViewController”,但我不知道该怎么做.
警告:尝试显示< AppName.PauseScreen:0x7fae61fe5ff0> on< AppName.StartScreenViewController:0x7fae61f79980>其视图不在窗口层次结构中!
(UIApplication.sharedApplication().delegate as AppDelegate).window?.rootViewController指向StartScreenViewController的一个实例.这很糟糕:rootViewController应该指向GameScene的一个实例.
根本原因必须是GameScene的呈现方式.从您的描述:
The “StartScreenViewController” is the view controller… It then goes to the “GameScene”…
这一定是您的问题所在.你如何从StartScreenViewController转到GameScene?
我的猜测是你要为应用程序添加一个新窗口.您需要设置rootViewController.
let gameScene = UIStoryboard(name: "Main",bundle:nil).instantiateViewControllerWithIdentifier("GameSceneID") as UIViewController let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate) appDelegate.window?.rootViewController = gameScene
当您返回到开始屏幕时,再次设置rootViewController.
let initialViewController = UIStoryboard(name: "Main",bundle:nil).instantiateInitialViewController() as UIViewController let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate) appDelegate.window?.rootViewController = initialViewController
您可以使用transitionFromViewController(,toViewController:,duration:,options:,animations:,completion:)
设置根视图控制器的动画.