Question

Hello I am trying to make a simple game where the game is a sprite kit scene, but the menus and game over screens are in story board. How can I switch from a scene to a UIView?

Was it helpful?

Solution

Use the following method: (I to suppose you have a rootViewController so that you may present the view, and also that the Views you wish to present have an identifier in the Storyboard, so that you may instantiate them)

Example:

//The method which presents the view you wish to display:

-(void)presentUIView{
    UIViewController *myview = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]instantiateViewControllerWithIdentifier:@"MyView"]; 
    [self.view.window.rootViewController presentViewController:myView animated:YES completion:nil];
}

//And then when you wish to dismiss the view to go back (called inside the View): 
-(void)dismissItself:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

Let me know if it works

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top