Moving between GameScene and ViewController Swift

99封情书 提交于 2019-12-07 18:00:28
BAP

I don't think this is what you're expected to do... You should be using an SKScene - instead of a UIViewController - for your navigation/menu.

But, one post I found did explain this (albeit it's in Obj-C):

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone"     bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"PurchasedVC"];
//Call on the RootViewController to present the New View Controller
[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];

The Swift version should look something like this (I'm no expert, but the syntax isn't too bad)...

var mainStoryboard = UIStoryboard(name: "Main_iPhone", bundle: nil)
var vc = mainStoryboard.instantiateViewControllerWithIdentifier("PurchasedVC") as! UIViewController
self.view.window?.rootViewController?.presentViewController(vc, animated: true, completion: nil)

In terms of other answers:

I hope that helps. I had the same question, and to be honest, it looks like I was just doing it wrong the whole time!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!