0

I my swiftui navigation stack i want to remove the back button from the view but i want to allow the user to move to the previous screen when it is pinched from the left hand side

@main
struct MyApp: App {
    
    @State private var path = [String]()
    
    var body: some Scene {
        WindowGroup {
            NavigationStack(path: $path){
                FirstView(path: $path)
            }.navigationDestination(for: String.self) { string in
                SecondView()
                
            }
        }
    }
}

Now in my SecondView i have added .navigationBarHidden(true) which removes the back button but also removes the ability to pinch back to the previous view

Go Fudge YourSelves
  • 139
  • 1
  • 2
  • 10

1 Answers1

1

You can find the answer here which works by extending UINavigationController and adding a UIGestureRecognizerDelegate.

ske57
  • 577
  • 4
  • 21
ezkeemo
  • 100
  • 8
  • How to use the extension? @ezkeemo – Go Fudge YourSelves Nov 15 '22 at 02:53
  • just add it somewhere in the project and that's it. Since SwiftUI uses UIKit under the hood, so this extension will handle the gestures inside any UINavigationController, NavigationStack in this case (unless you change it for your future needs) – ezkeemo Nov 15 '22 at 11:44