Go from SKView back to UIView

2020-02-09 14:52发布

I have two parts to my project. Part one is made in the storyboard, and the second is an SKView. How can I go from my second part in the SKView back to the main UIView?

1条回答
对你真心纯属浪费
2楼-- · 2020-02-09 15:36
  1. Create custom ViewController: File - New - File - Objective-C class. Enter a name: GameSceneViewController. Subclass of UIViewController.

  2. Override viewWillAppear method:

    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        GameScene *scene = [[GameScene alloc] initWithSize:self.view.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
    
        [self.skView presentScene:scene];
    }
    

    skView property will be an IBOutlet for SKView. Also make sure you've imported SpriteKit framework:

    #import <SpriteKit/SpriteKit.h>
    
  3. Add new ViewController to the storyboard.

  4. In the Identity inspector enter a custom class for the added ViewController: GameSceneViewController

    GameSceneViewController

  5. Add a subview to a root view:

    GameSceneViewController

  6. In the Identity inspector enter a custom class for the added View: SKView

    Custom class name

  7. Create an IBOutlet for the added SKView.

Now you should be able to use segues for switching between ViewControllers

查看更多
登录 后发表回答