如何从 SKScene 中执行 segue? [英] How to perform segue from within a SKScene?
问题描述
我一直在尝试从 sprite kit SKScene 层中执行转场.我的应用程序要求用户触摸场景上的图像,这会推动新的 UIViewController.但是每次我尝试从 SKScene 游戏层中执行时,它都会给我输出没有带有标识符错误的 segue.我确实有一个 segue 并用标识符指定了它.
I have been trying to perform a segue from within a sprite kit SKScene layer. My application requires the user to touch an image on the scene that would push up a new UIViewController. But every time I try to perform from within the SKScene game layer, it gives me output with has no segue with identifier error. I do have a segue and have specified it with an identifier.
我的简单问题是,如何在运行 SKScene 游戏层的情况下进行 segue?请帮帮我.
My simple question, how can one perfrom segue with a SKScene game layer running? Please help me out.
推荐答案
Segues 属于视图控制器,而不是 SpriteKit 场景.如果您想从 SpriteKit 节点的事件处理代码中执行 segue,您需要查找拥有呈现场景的视图的视图控制器.例如,在 SKScene
子类的 touchesBegan:withEvent:
方法中:
Segues belong to view controllers, not SpriteKit scenes. If you want to perform a segue from within a SpriteKit node's event handling code, you'll need to look up the view controller that owns the view presenting the scene. For example, in a SKScene
subclass' touchesBegan:withEvent:
method:
UIViewController *vc = self.view.window.rootViewController;
[vc performSegueWithIdentifier:@"id" sender:nil];
这篇关于如何从 SKScene 中执行 segue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!