我正在寻找使用SpriteKit从gameScene更改我的ViewController。 我有3个不同的ViewControllers场景。如何在SKScene中的几个ViewController之间进行转换?
当我的应用程序以PresentationViewController开头时(参见截图1),我从GameScene(GameViewController)到GameOverViewController的转换代码不起作用,我可以读取一条错误消息。
错误消息:
whose view is not in the window hierarchy!
我的代码是:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let settingController: UIViewController = storyboard.instantiateViewControllerWithIdentifier("PresentationViewController") as UIViewController
let vc = self.view?.window?.rootViewController
vc?.presentViewController(settingController, animated: true, completion: nil)
而当我的应用程序与GameViewController开始(见截图2)过渡代码完美。
我不知道为什么会出现这2个病例之间的差异。
有关信息PresentationViewController和GameViewController之间的过渡是与此代码的UIButton:
override func viewDidLoad() {
super.viewDidLoad()
var playButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
let image = UIImage(named: "playButton.png") as UIImage
playButton.frame = CGRectMake(0, 0, 100, 100)
playButton.center = CGPointMake(self.view.frame.width/2, self.view.frame.height/1.7)
playButton.addTarget(self, action: "transition:", forControlEvents: UIControlEvents.TouchUpInside)
playButton.setBackgroundImage(image, forState: UIControlState.Normal)
self.view.addSubview(playButton)
}
func transition(sender:UIButton!)
{
println("transition")
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("GameViewController") as UIViewController
secondViewController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
self.presentViewController(secondViewController, animated: true, completion: nil)
}