Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide status bar whenever nav bar is hidden - SWIFT iOS8

How can I had the status bar whenever the view is scrolling with:

    self.navigationController?.hidesBarsOnSwipe = true

or if not hide the status bar, how can I keep my status bar from overlaying my view?

ty awesome stackoverflow community

like image 828
John D Avatar asked Dec 22 '14 23:12

John D


2 Answers

A Swift 3 elegant solution:

open override var prefersStatusBarHidden: Bool {
    return navigationController?.isNavigationBarHidden ?? false
}
like image 179
luizv Avatar answered Sep 28 '22 17:09

luizv


Sorry if this answer is a little late, but here is one way to do it.

Use the prefersStatusBarHidden() method within your view controller.

override func prefersStatusBarHidden() -> Bool {
    if self.navigationController?.navigationBarHidden == true {
        return true
    } else {
        return false
    }
}

Basically says that when the Nav bar is hidden, then the status bar is too and vice versa.

like image 38
Demonic Penguin Avatar answered Sep 28 '22 15:09

Demonic Penguin