Firstly, you don't need to have this isPresentedSettings variable for presenting a NavigationLink.NavigationLink(destination: SettingsPageView()) { Text("Button")}并且您的视图层次结构中应该只有一个 NavigationView.And there should be only one NavigationView in your view hierarchy.您的最终代码如下所示:This is how your final code can look like:struct ContentView: View { @State private var navBarHidden = true var body: some View { NavigationView { ZStack { VStack { SettingsButton(navBarHidden: $navBarHidden) } } .navigationBarHidden(navBarHidden) } }}struct SettingsButton: View { @Binding var navBarHidden: Bool var body: some View { NavigationLink(destination: SettingsPageView(navBarHidden: $navBarHidden)) { Text("Show View") } }}struct SettingsPageView: View { @Binding var navBarHidden: Bool var body: some View { VStack { Text("This is a view") } .navigationBarTitle("Settings", displayMode: .inline) .onAppear { self.navBarHidden = false } .onDisappear { self.navBarHidden = true } }} 这篇关于SwiftUI 仅在查看 ContentView 时隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-04 22:08