您好,我已经看到很多关于这个主题的问题,但似乎没有一个能解决我的问题。当用户获胜/死亡时,我想在 SKScene 上显示一个 UIView Controller 。我创建了一个 PresentWinLoseViewController : UIViewController 子类并将其连接到 Storyboard中。我在 Storyboard 中创建了一个从 GameViewController 到 PresentWinLoseViewController 的转场,以及从 PresentWinLoseViewController 回到 GameViewController 的两个退出转场。
我是这样调用它们的。当我赢/输时在我的 SKScene 中
func win() {
let gameVC = GameViewController()
gameVC.performSegueWithIdentifier("tryAgain", sender: self)
}
和我从 PresentWinLoseViewController 退出 segues
@IBAction func tryAgainButtonPressed(segue:UIStoryboardSegue) {
self.performSegueWithIdentifier("unwindTryAgain", sender: self)
}
但我什至不能走那么远,因为第一个 segue 从来没有用过。我不断得到
Receiver (<SpriteLevelBuilder.GameViewController: 0x7ff2b5e49210>) has no segue with identifier 'tryAgain''
我做错了什么?
最佳答案
对于初学者来说,GameViewController 应该已经初始化,没有必要 let gameVC = GameViewController()
这是因为您的 SKScene 实际上是由您的 GameViewController 呈现的。去看看你的 GameViewController,你应该在 viewDidLoad() 中看到 SKScene 的初始化过程。
由于 GameViewController 已经初始化,您需要做的就是直接从 SKScene 调用 GameViewController 上的 performSegueWithIdentifier。
我只是进行了快速搜索,这个答案似乎适用于您的情况:How to call method from ViewController in GameScene
关于ios - 如何在 spritekit 场景上呈现 uiviewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29243144/