Search code examples
iosobjective-cuiviewsprite-kitskview

Show UIView in front of SKView - iOS - SpriteKit


I have a simple little Sprite Kit game for iOS. I am trying to get my UIView (which contains main menu buttons/title) to appear above the SKView where some nice moving animations are happening. This is not for game play, that is on a separate view.

I have setup a UIView (which has its class set to SKView) and another UIView onto of that which has all the UIButtons and the game title.

However, I can't seem to get the SKView to appear above my UIView which contains the buttons/title.

The general reason as to why I am trying to do this is that on the main menu I want some nice continuous animations to happen in the background as a sort of nice effect while the user decides to select whichever button. I can just try and do the animations which some methods and very basic UIView Animation code, but then the UI gets blocked and its just a pain to get it to work, thus SpriteKit animation is much much better and smoother.

Here is how I'm trying to do it:

// In header file:
IBOutlet UIView *anim_view;

// In implementation file:
// Configure the view.
SKView *skView = (SKView *)anim_view;
// Instead of ... self.view ... I have anim_view    

skView.showsFPS = NO;
skView.showsNodeCount = NO;

// Create and configure the scene.
SKScene *scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;

// Present the scene.
[skView presentScene:scene];

In my storyboard file I have two UIViews as I talked about like so:

Storyboard UIView setup image

How can I get around this issue?

Thanks for your time, Dan.


Solution

  • SKView is based on UIView, just swap between them rather than trying to stack them up.

    [UIView transitionFromView:self.view toView:MySecondView duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
        // What to do when its finished.
    }];
    

    See this answer: https://stackoverflow.com/a/11848297/183