切换到GameScene.swift查看控制器

时间:2023-01-23 22:34:01

I have a View Controller called "MenuVC" in my Main.Storyboard file. I want to show this View Controller programmatically from my GameScene.swift file.

我在Main.Storyboard文件中有一个名为“MenuVC”的View Controller。我想以编程方式从我的GameScene.swift文件中显示此View Controller。

2 个解决方案

#1


0  

Somewhere in GameScene.swift file:

在GameScene.swift文件中的某个地方:

//...
let vc = self.storyboard?.instantiateViewController(withIdentifier: "MenuVC") as! MenuVC
self.present(vc, animated: true, completion: nil)
//...

But here is the full answer: Swift programmatically navigate to another view controller/scene

但这里有完整的答案:Swift以编程方式导航到另一个视图控制器/场景

#2


0  

First set the view controller storyboard id in storyboard.

首先在storyboard中设置视图控制器故事板ID。

切换到GameScene.swift查看控制器

And then

let menuVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MenuVC" as! MenuVC

And if you are using navigation controller

如果您正在使用导航控制器

self.navigationController?.pushViewController(menuVC, animated: true)

Or you can present it.

或者你可以呈现它。

self.present(menuVC, animated: true, completion: nil)

#1


0  

Somewhere in GameScene.swift file:

在GameScene.swift文件中的某个地方:

//...
let vc = self.storyboard?.instantiateViewController(withIdentifier: "MenuVC") as! MenuVC
self.present(vc, animated: true, completion: nil)
//...

But here is the full answer: Swift programmatically navigate to another view controller/scene

但这里有完整的答案:Swift以编程方式导航到另一个视图控制器/场景

#2


0  

First set the view controller storyboard id in storyboard.

首先在storyboard中设置视图控制器故事板ID。

切换到GameScene.swift查看控制器

And then

let menuVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MenuVC" as! MenuVC

And if you are using navigation controller

如果您正在使用导航控制器

self.navigationController?.pushViewController(menuVC, animated: true)

Or you can present it.

或者你可以呈现它。

self.present(menuVC, animated: true, completion: nil)