我遇到一个问题,我的文本在导航栏后面消失了。用户单击“设置”(或任何其他菜单按钮)后,导航栏将变为可见。它会显示出来并且内容可见,但是在完成加载新视图后,文本会消失在栏后面。有什么办法吗?
我更改了导航栏的状态,该导航栏的显示级别是根级视图的.onAppear和.onDisappear。
编写如下代码:
struct ContentView: View {
@State public var navBarHidden = true
var body: some View {
NavigationView{
VStack{
ZStack(alignment: .center){
WhiteImage().onAppear{self.navBarHidden = true} //Here only seen as white background
BottomButtons().onDisappear{self.navBarHidden = false}
ProfileInvoke().navigationBarTitle("").navigationBarHidden(self.navBarHidden)
}
}
}
}
}
//The buttons are done with such a construct
struct MenuButton: View {
var buttonText: String
var buttonCallView: AnyView
var body: some View {
NavigationLink(destination: self.buttonCallView) {
Text(self.buttonText)
}.padding()
}
}
//Population of a button
MenuButton(buttonText: "My Favourites", buttonCallView: AnyView(MyFavouritesView().navigationBarTitle(Text("My Favourites"), displayMode: .inline)))
// The settings view where the title disappears
struct SettingsView: View {
var body: some View {
HStack(alignment: .top){
VStack(alignment: .leading){
Text("General").bold()
Divider()
Spacer()
}.padding()
Spacer()
}
}
}
我觉得这与.onAppear
和.onDisappear
有关,在这里我将导航栏的状态设置为隐藏还是不隐藏。不确定