aaisataev
aaisataev

Reputation: 1683

Show status bar when hide navigation bar

I hide navbar when user scrolls the table up.

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
    if self.navigationController?.navigationBarHidden == false {
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }
}

But this method also hides the status bar.

Can't keep my status bar. These methods don't work:

UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .None)
prefersStatusBarHidden()

Please, help!

Upvotes: 4

Views: 3941

Answers (3)

aaisataev
aaisataev

Reputation: 1683

Was my mistake. Status bar wasn't hidden, it was just white like a table view background. Just set this when nav bar is hidden:

UIApplication.shared.statusBarStyle = .default

Upvotes: 2

Ketan P
Ketan P

Reputation: 4379

if you are want to hide and show just navigation bar on scrollView.

you can override viewDidAppear. & use hidesBarsOnSwipe property of navigation controller.

override func viewDidAppear(animated: Bool) {

    super.viewDidAppear(animated)
    
    navigationController?.hidesBarsOnSwipe = true

}

Hope This Answer helps you.

Upvotes: 5

vien vu
vien vu

Reputation: 4337

Try make a variable shouldHideStatusBar

And override this func:

override func prefersStatusBarHidden() -> Bool {
    return shouldHideStatusBar
}

when scroll put it:

shouldHideStatusBar = true/false
self.setNeedsStatusBarAppearanceUpdate()

Hope this help.

Upvotes: 3

Related Questions