【发布时间】:2014-10-10 21:05:14
【问题描述】:
我正在寻找使用 SpriteKit 从 gameScene 更改我的 ViewController。 我有 3 个场景和 3 个不同的 ViewControllers。
当我的应用程序以 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),转换代码运行良好。
我不知道为什么这两种情况有区别。
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)
}
【问题讨论】:
标签: ios swift sprite-kit viewcontroller skscene