How to hide the status bar programmatically in iOS

2019-06-22 06:42发布

This question already has an answer here:

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

标签: swift ios8
2条回答
神经病院院长
2楼-- · 2019-06-22 07:10

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

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

enter image description here

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

查看更多
做自己的国王
3楼-- · 2019-06-22 07:28

This should do the trick:

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

See this answer for more details.

查看更多
登录 后发表回答