1
votes

I'm still learning to SwiftUI and am playing with the NavigationView and I am able to hide the top navigation bar in portrait mode but have two issues.

1.) In landscape mode, there's a top bar that still sits on top of the view. Pulling it down brings down the notification center/settings

2.) After tapping the button in the view, it moves to the DetailView, but the top navigation bar is loaded briefly and then hides. How to stop the navigation from loading.

GIF of button to next view - the flow from tapping button to moving to next view to changing to landscape mode

Any feedback or approach is appreciated. Thanks!

struct ContentView: View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: DetailView()) {
                    Text("Hello World")
                    .fontWeight(.bold)
                    .font(.title)
                    .padding()
                    .background(Color.blue)
                    .cornerRadius(40)
                    .foregroundColor(.blue)
                    .padding(10)
                    .overlay(
                        RoundedRectangle(cornerRadius: 40)
                    )
                }
                .navigationBarTitle("", displayMode: .inline)
                .navigationBarHidden(true)
                .navigationBarBackButtonHidden(true)
                //.edgesIgnoringSafeArea([.top, .bottom])
                //.navigationViewStyle(StackNavigationViewStyle())
                //.navigationViewStyle(DoubleColumnNavigationViewStyle())

            }
        }
        .navigationBarTitle("", displayMode: .inline)
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true)
        //.statusBar(hidden: true)
    }
}
1
Figured it out. It was just the placement of the methods. Placing them immediately after NavigationLink worked.s14evo3

1 Answers

2
votes

I was also seeing the navigation bar shown briefly in the destination view before it disappeared. To fix that, I added the navigation bar properties to the destination view argument inside the NavigationLink call. For your example, it would look like this:

struct ContentView: View {
var body: some View {
    NavigationView {
        VStack {
            NavigationLink(destination: DetailView()
            .navigationBarTitle("", displayMode: .inline)
            .navigationBarHidden(true)
            .navigationBarBackButtonHidden(true)
            ) { // The rest of your code...