1
votes

I'm trying to hide my Status Bar and Navigation bar when the view is tapped. Currently I found something that works from a previous question, but the problem is that there is no animation when hiding the bars. It just disappears.

Here is my current code in my View Controller:

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

When I tap again, the animation works when the two bars are coming back on to the screen.

If I don't include the overrided prefersStatusBarHidden function, I can get the navigation bar to hide with the desired sliding animation. But the status bar is still there.

Any suggestions? Does Swift 2 have a new method that can work?

2

2 Answers

2
votes

Try this

var statusBarHidden = false

      func tapAction() {
    self.navigationController?.navigationBarHidden = true 
    self.statusBarHidden = true
        self.setNeedsStatusBarAppearanceUpdate()
        }

     override  func prefersStatusBarHidden() -> Bool {
            return  statusBarHidden
        }
0
votes

Have you set View controller-based status bar appearance = NO in the info.plist?