从SKscene(SpriteKit)呈现UIViewController [英] Presenting a UIViewController from an SKscene (SpriteKit)

查看:90
本文介绍了从SKscene(SpriteKit)呈现UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

互联网上有几篇帖子询问如何正确组合SpriteKit和Storyboard / Interface构建器。特别是没有人能够从SKscene移动到期望的UIViewController。网上的解决方案没有真正解决这个问题!这真的不可能吗?如果是这样,那将是SpriteKit的重大限制......

There are several posts on the internet asking how to correctly combine SpriteKit and Storyboard/Interface builder. In particular nobody is able to move from an SKscene to a desired UIViewController. NONE of the solutions on the net really address this problem! Is it really not possible to do this?? If so, it would be a significant limitation of SpriteKit...

推荐答案

你不能直接从 SKScene 到另一个 UIViewController

You cannot move directly from an SKScene to another UIViewController.

然而, SKScene UIViewController 中已经包含

您可以使用委派将方法调用从场景传递到其控制器。然后控制器可以移动到另一个视图控制器。

You can use delegation to pass a method call from the scene to its controller. The controller can then move to another view controller.

所以......


  1. 创建一个包含类似...的方法的委托协议 - (void)transitionToOtherViewController;

将当前视图控制器设置为场景的委托。

Set the current view controller as the delegate of your scene.

self.scene.delegate = self;

当您想要移动到另一个视图控制器时。在场景中你会有类似......

When you want to move to another view controller. In the scene you would have something like...

[self.delegate transitionToOtherViewController];

然后在视图控制器中你有......

Then in the view controller you have...

- (void)transitionToOtherViewController
{
    MyOtherViewController *controller = [MyOtherViewController new];

    [self.navigationController pushViewController:controller animated:YES];
}

或类似的东西......

Or something like this...

这篇关于从SKscene(SpriteKit)呈现UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆