Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show/hide the status bar on a pageViewController using tap gesture (iOS8 / Swift)

Looking through all the solutions given to similar questions, I have been trying to get the statusBar to show/hide with a tap gesture.

I have set View controller-based status bar appearance = NO in the plist.

I have tried the following code in my DataViewController (page view controller) AND in the RootViewController:

let app = UIApplication.sharedApplication()
app.setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Fade)

and it doesn't work.

This is embedded in a UITabBarController, would that make a difference?

Also, I was able to get the following to hide the statusBar from the RootViewController:

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

But the DataViewController does not even call this function, and was only able to hide it permanently this way, rather than toggle it on/off.

Any ideas?

like image 694
Michael Campsall Avatar asked Nov 20 '14 05:11

Michael Campsall


1 Answers

I have tried it in code, everything works fine for me. Make sure that the View controller-based status bar appearance is Set to NO. And there is no needs to override prefersStatusBarHidden().

like image 145
liuyaodong Avatar answered Nov 14 '22 16:11

liuyaodong