NavigationView我正在使用and为我的游戏制作菜单NavigationLink。我有这样的三个观点:
NavigationView
NavigationLink
struct MainMenuView: View { var body: some View { NavigationView { // relevant stuff NavigationLink(destination: CustomGameSettingsView()) { Text("Custom Game") } } } } struct CustomGameSettingsView: View { var body: some View { NavigationView { // ui to change game settings and stuff NavigationLink(destination: MyGameView(customSettings)) { Text("Play Game!") } } } }
请注意,CustomGameSettingsView显示navigationBarBackButton
CustomGameSettingsView
navigationBarBackButton
struct MyGameView: View { var body: some View { myGameViews { // stuff } .navigationBarBackButtonHidden(true) .navigationBarHidden(true) .navigationBarTitle(Text("myGame")) .edgesIgnoringSafeArea([.top, .bottom]) // these are the things I have tried to get rid of the navigationBackButton } .onAppear() { self.navigationBarBackButtonHidden(true) } // another thing I tried }
当我从MainMenuViewto导航时,当我导航到 时CustomGameSettingsView,我会得到一个navigationBarBackButton留在我身边的MyGameView。我如何在最终导航中摆脱它?我想要设置菜单上的后退按钮,但我希望我的游戏是全屏的。在这种情况下是NavigationView错误的工具吗?
MainMenuView
MyGameView
先感谢您。
这里的问题是你NavigationView{}在CustomGameSettingsView. 您不必使用另一个NavigationView ,因为您的所有视图( MainMenuView除外)都已经在MainMenuView.
NavigationView{}
要解决此问题,请将其中的NavigationView替换为不同的容器CustomGameSettingsView,然后一切正常。另外,删除所有onAppear{}.
onAppear{}
struct CustomGameSettingsView: View { var body: some View { VStack { //replace NavigationView with something else NavigationLink(destination: MyGameView()) { Text("Play Game!") } } } }