UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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)

3      

@jgc92  

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

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.