How to hide the status bar programmatically in iOS

2019-06-22 06:31发布

问题:

This question already has an answer here:

  • How to hide iOS status bar 20 answers

Just like the question says, I need to hide status + navigation bar when user taps. So far, navigation bar was easy. Cann't find a way to do the same with status bar.

By the way, tried

UIApplication.sharedApplication().statusBarHidden = true

but no luck yet

回答1:

You should add this key/value pair to your project's Info.plist.

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

After that,calling

UIApplication.sharedApplication().statusBarHidden = true

or

UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade) // with animation option.

This post gives more details > How to hide iOS status bar



回答2:

This should do the trick:

UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Slide)

See this answer for more details.



标签: swift ios8