skip to Main Content

I am using xcode 13.2.1 iOS 15,i want to hide the navigational bar and the back arrow i have tried several methods. none of the answers worked

var body: some View {
    NavigationView{
        ZStack{
                Text("Header") //Header View
                Spacer ()
                Text("Main")//Main View
                Spacer()
                Spacer()
                Text("Bottom") //Bottom View
        }.navigationTitle("")
        .navigationBarHidden(true)
        
    }.navigationViewStyle(.stack)
}

2

Answers


  1. I fixed this on xcode 12.5 by adding this:

    class AppDelegate: NSObject, UIApplicationDelegate {
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
            UIApplication.shared.isStatusBarHidden = true // <== ADD THIS LINE
            return true
        }
    }
    

    and then under info.plist I added

    <key>UIStatusBarHidden</key>
    <true/>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    

    using xml type.

    Also I had .navigationBarHidden(true) on the upmost level in the view, so for you, the NavigationView.

    Login or Signup to reply.
  2. A better SwiftUI approach is to create a @State property to toggle the state.

    @State private var hideNavigationbar: Bool = false
    

    You switching the value in .onAppear {} to true. When you dismiss the view you call .onDisappear {} and set the property to false.

    Now you can use it like so:

    .navigationbarHidden(hideNavigationbar)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search