Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

sprite kit - Go from SKView back to UIView

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...