我正在尋找使用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)
}