简体   繁体   中英

Hide status bar on iOS Swift

In my application, for a particular screen, I need to hide the status bar. My screen hierarchy is:

MainScreen -> ScreenA -> ScreenB -> Screenc

In My Screenc I need to hide the status bar. So I am doing like this:

 override var prefersStatusBarHidden: Bool {
        return true
    }

It's working fine. But when I push back from Screenc my ScreenB, ScreenA status bar and my nav bar are overlapping. Like my ScreenB, ScreenA title , right bar button , and all overlap with status bar. But my status bar is also showing in ScreenB, ScreenA .

Not sure why it's happening. In my plist file I have:

View controller-based status bar appearance : YES

I can't change this to NO. Because in my application I am using fixing portrait to particular viewcontroller.

Any solution to how can I fix these issues?

What you can do is to show and hide in Appear and Disappear

   override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.isNavigationBarHidden = true
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.isNavigationBarHidden = false
    }

In viewDidLoad() function add

self.navigationController?.isNavigationBarHidden = true

And in your previous ViewController on viewDidAppear method add

self.navigationController?.isNavigationBarHidden = false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM