在iOS中隐藏状态栏而不删除其视图 [英] Hide status bar in iOS without removing its view
问题描述
我想在按下按钮时隐藏我的iPhone应用程序中的状态栏,并且想在再次按下按钮时再次显示它.
I want to hide status bar in my iPhone app on a button press and I want to show it again on pressing another button.
我试图通过覆盖视图控制器中的-(BOOL)prefersStatusBarHidden
来隐藏状态栏,但这也会从顶部删除其视图.
I tried to hide the status bar by overriding -(BOOL)prefersStatusBarHidden
in my view controller but this also removes its view from the top.
因此,在删除此状态栏时可以看到一个跳跃.我想做的只是在保留状态栏背景的同时隐藏状态栏上的内容.
例如:您可以在gmail应用程序中检查相同的功能.在gmail应用中打开侧边抽屉时,只有状态栏上的内容被隐藏,并且没有跳转.
So a jump is seen on removing this status bar. What I want to do is just to hide the content on the status bar while keeping the background of status bar.
For example: You can check the same functionality in gmail app. When you open the side drawer in gmail app, then only the contents on status bar are hidden and there is no jump.
推荐答案
我通过iOS13的 additionalSafeAreaInsets
属性修复了此问题.在iOS13上,没有其他解决方案对我有用.隐藏状态变量时,将 additionalSafeAreaInsets
的最高值设置为 20
,取消隐藏时将其再次设置为 0
.
I fixed this problem with additionalSafeAreaInsets
property at iOS13. No other solution worked for me at iOS13.
When hiding status var set additionalSafeAreaInsets
top value to 20
, when unhiding set it again to 0
.
对于带有槽口的设备,无需更改安全区域插图.仅对其他设备执行此操作.
For devices with notch no need to change safe area insets. Do this for only other devices.
这篇关于在iOS中隐藏状态栏而不删除其视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!