【发布时间】:2020-06-03 22:29:20
【问题描述】:
我有一个内容文件并隐藏导航栏,因为它占用空间并将元素向下推。 ContentView 中的一个按钮重定向(使用导航链接)到另一个视图。在另一个视图中,navigationBar 仍然是隐藏的……为简单起见,我将从 ContentView 中删除一些代码:
//this is the view that looks "fine" (i.e. the navigation bar takes up no space)
struct ContentView: View {
@State private var isPresentedSettings = false
var body: some View {
NavigationView {
ZStack {
VStack {
SettingsButton(isPresentedSettings: $isPresentedSettings)
}
}.navigationBarTitle("").navigationBarHidden(true)
}
}
}
//this is the button that pulls up the settings page view
struct SettingsButton: View {
@Binding var isPresentedSettings: Bool
var body: some View {
NavigationLink (destination: SettingsPageView(isPresentedSettings:
self.$isPresentedSettings)) {
Button(action: { self.isPresentedSettings.toggle() }, label: { Text("Button") })
}
}
}
//This is the view that should have a navigationbar but it doesn't
struct SettingsPageView: View {
@Binding var isPresentedSettings: Bool
var body: some View {
NavigationView {
VStack {
Text("This is a view")
}.navigationBarTitle("Settings", displayMode: .inline)
}
}
}
另外...可能有错别字,因为我刚刚从另一台计算机复制代码。抱歉,提前谢谢您!
【问题讨论】:
标签: swift swiftui navigationbar navigationview