How do I hide the status bar in an iOS app without causing the UINavigationBar to jump?

放肆的年华 提交于 2019-12-11 16:48:25

问题


I have a view controller that needs to hide the status bar before presenting a modal and after that modal is dismissed.

This is not as simple as overriding prefersStatusBarHidden and then setting modalPresentationCapturesStatusBarAppearance because that will also cause a jump given I am presenting over the current context (the modal is a pull down to dismiss).

Consider the instagram story UX, as an example. When tapping on a story, you actually see the status bar disappear before the story modal is presented. Then when pulling the story down to dismiss it, the modal view controller actually must be completely dismissed before they redisplay the status bar.

I originally implemented a custom status bar that would do a lot of tricks to maintain the proper size and position given the device / iOS combos (iOS 10 & 11 + iPhone X and non iPhone X) but that was proving to be very painful unless I detected the device and hardcoded the safe area / layout guide dimensions. So currently I am attempting to do this with the stock UINavigationBar.

Any idea how this is possible?

来源:https://stackoverflow.com/questions/50771879/how-do-i-hide-the-status-bar-in-an-ios-app-without-causing-the-uinavigationbar-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!