Presenting a UIViewController from an SKscene (SpriteKit)

孤街醉人 提交于 2019-12-10 10:38:53

问题


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...


回答1:


You cannot move directly from an SKScene to another UIViewController.

However, the SKScene is already contained in a 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.

So...

  1. Create a delegate protocol that contains a method something like... - (void)transitionToOtherViewController;

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

    self.scene.delegate = self;

  3. 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...



来源:https://stackoverflow.com/questions/23930592/presenting-a-uiviewcontroller-from-an-skscene-spritekit

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