NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Is there a way to dismiss a SwiftUI view from within a SpriteView scene?

Forums > SwiftUI

My scene is presented like this

struct GameView: View {
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>

    func scene(size:CGSize) -> SKScene {
        let scene = GameScene()
        scene.size = size
        scene.scaleMode = .fill
        scene.physicsWorld.gravity = CGVector.zero
        return scene
    }

    var body: some View {
        GeometryReader { geometry in
            if #available(iOS 14.0, *) {
                SpriteView(scene: self.scene(size:geometry.size))
                    .edgesIgnoringSafeArea(.all)
            } else {
                // Fallback on earlier versions
                Text("Game Only available from iOS 14")
            }
        }
        .navigationTitle("")
        .navigationBarHidden(true)
    }
}

In other non spriteKit views I have used self.presentationMode.wrappedValue.dismiss() to navigate back to the previous page. Is there something similar I can do in this case once the end of the game has been triggered from within the scene? (All the views are within a navigation view)

   

@jgc92  

Hi, I'm stuck with the same problem. Have you find the answer?

   

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.