English 中文(简体)
A. 导航中的探测 在消失之前打扫清屏
原标题:Popping from NavigationStack clears screen before disappearing
The bounty expires in 3 days. Answers to this question are eligible for a +100 reputation bounty. Nicolas Gimelli wants to draw more attention to this question.

由于某种原因,与经常开除相比,清理航行舱位会造成意外估计。 它清除了面前的屏幕实际上消失了。 如果不清除屏幕,你怎么能够重新扎根?

https://imgur.com/a/GYhtmCK

struct ContentView: View {
    @State var navigationPath: NavigationPath = NavigationPath()
    
    var body: some View {
        NavigationStack(path: $navigationPath) {
            ZStack {
                Color.red
                NavigationLink(value: 0) {
                    Text("test")
                }
            }
            .navigationDestination(for: Int.self) { _ in
                SubView(navigationPath: $navigationPath)
            }
        }
    }
}

struct SubView: View {
    @Binding var navigationPath: NavigationPath
    
    var body: some View {
        ZStack {
            Color.green
            Button {
                navigationPath = NavigationPath()
            } label: {
                Text("back")
            }

        }
    }
}
问题回答

How can you pop back to root normally without the clearing of the screen? You could try this alternative approach, using dismiss() to go back, works for me.

struct ContentView: View {
    @State var navigationPath: NavigationPath = NavigationPath()
    
    var body: some View {
        NavigationStack(path: $navigationPath) {
            ZStack {
                Color.red
                NavigationLink(value: 0) {
                    Text("test")
                }
            }
            .navigationDestination(for: Int.self) { val in
                SubView() // <-- here
            }
        }
    }
}

struct SubView: View {
    @Environment(.dismiss) var dismiss  // <-- here
    
    var body: some View {
        ZStack {
            Color.green
            Button {
                dismiss() // <-- here
            } label: {
                Text("back")
            }
        }
    }
}




相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

BraintreeDropIn deprecated functions error

I m getting this error on the latest release of BraintreeDropIn, I really don t get it since based on the patch notes, this should ve been addressed already, I have already tried cleaning derived data,...

how to limit zoom level in map swift ui?

how to limit zoom level in map swift ui i have map and need to make zoom level limited Map(coordinateRegion: $region,annotationItems: viewModel.nearbyGyms) { item in ...

UIImageView - How to get the file name of the image assigned?

Is it possible to read the name of an UIImageView s UIImage that s presently stored in the UIImageView? I was hoping you could do something kind of like this, but haven t figured it out. NSString *...

热门标签