N
N
Nikita2020-05-13 19:48:02
iOS
Nikita, 2020-05-13 19:48:02

How to hide NavigationBar in SwiftUI on all devices the same way?

Good evening!
I have the following View hierarchy: SplashView -> MainView.
In SplashView I don't need NavigationBar, so I turn it off:

NavigationView {
        VStack { /* some stuff */}        
    }    
         .navigationBarTitle("", displayMode: .inline)
         .navigationBarHidden(true)
         .edgesIgnoringSafeArea([.top, .bottom])


In MainView I need an inline NavigationBar:
NavigationView {
        ZStack{ /* some stuff */ } 
        }.navigationBarTitle("TEST TITLE", displayMode: .inline)
            .navigationBarHidden(false)
            .navigationBarBackButtonHidden(true)
            .navigationBarItems(leading: EmptyView())
            .navigationBarItems(trailing: HStack {
                           Button("Test1") { print("test1")

                           }
                           Button("Test2") {
                               print("test2")
                   }
                       })
        }


As a result, on the iPhone 11 I get:

5ebc242256a25883414166.png

And on the iPhone SE 2nd gen. it is stretched and with extra buttons:

5ebc2460eb817183532513.png

Moreover, if you manage, you can click on the "Back" button and get back to SplashView!

Why does it work this way and how can it be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2020-05-13
@snitron

https://stackoverflow.com/questions/61780084/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question