HomeiOS Developmentios - Take away background from NavigatoinStack in SwiftUI

ios – Take away background from NavigatoinStack in SwiftUI


In my app, I wish to assemble a single background view underneath my NavigationStack after which present that very same background beneath different views that I navigate to through NavigationLinks. I’m attempting to do that by placing the NavigationStack and my background in a ZStack, however after inspecting the view hierarchy of the app I can see that the NavigationStack is exhibiting its personal background within the internet hosting view controller, and I am unable to for the lifetime of me work out the way to make it clear.

Here’s a simplified model of my view:

struct Drawer: View {
    @State non-public var choice: DrawerMenuItem? = DrawerMenuItems().choices.first

    var physique: some View {
        ZStack {
            Colour.blue.ignoresSafeArea()
            
            NavigationStack(path: $path) {
                Listing(DrawerMenuItems().choices, choice: $choice) { merchandise in
                    NavigationLink(vacation spot: AnyView(merchandise.view)) {
                        //Trimmed for brevity
                    }
                }
                .scrollContentBackground(.hidden)
            }
        }
    }
}

And here’s a screenshot of the ensuing view hierarchy:

View Hierarchy

I’m at present utilizing Xcode 15 beta with Swift 5, concentrating on iOS 17.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments