i've been searching through quite a lot of questions regarding this issue in iOS 8 here on *, but i haven't quite found one that could help me fix my particular situation.
我在*上一直在iOS 8中搜索关于这个问题的很多问题,但是我还没有找到一个可以帮我修复我的特殊情况的问题。
In my application i have a button that will enter a full screen mode, in this case it will just hide a navBar that i've coded and i'd like it to hide the status bar as well.
在我的应用程序中,我有一个按钮,将进入全屏模式,在这种情况下,它只会隐藏我编码的导航栏,我也希望它隐藏状态栏。
Using
[[UIApplication sharedApplication] setStatusBarHidden:YES];
I am successfully able to hide the status bar and enter said full screen mode, the problem happens when try to leave that mode and use the counter instruction
我成功地能够隐藏状态栏并进入所述全屏模式,当尝试离开该模式并使用计数器指令时会出现问题
[[UIApplication sharedApplication] setStatusBarHidden:NO];
This will work fine for the portrait orientation but if i rotate the device and go to landscape the usual default behaviour in iOS 8 is to hide the status bar but since i manually set it to NO in the instruction above it will overwrite that behaviour and it will always show the status bar on all the views in my app if i'm in landscape orientation.
这对于纵向方向可以正常工作但是如果我旋转设备并转向横向,iOS 8中的通常默认行为是隐藏状态栏但是因为我在上面的指令中手动将其设置为NO,它将覆盖该行为并且它如果我是横向的,我将始终在我的应用中的所有视图上显示状态栏。
So my question is, is there a way to restore the default behaviour of iOS 8 of hiding the status bar while in landscape?
所以我的问题是,有没有办法恢复iOS 8隐藏状态栏的默认行为?
2 个解决方案
#1
The solution I came up with:
我提出的解决方案:
I use a UINavigationController as the "super controller" of all my view controllers.
我使用UINavigationController作为所有视图控制器的“超级控制器”。
I subclassed the UINavigationController. In there I implement - (BOOL)prefersStatusBarHidden
and in my view controllers I call:
我将UINavigationController子类化。在那里我实现 - (BOOL)prefersStatusBarHidden并在我的视图控制器中调用:
- (BOOL)prefersStatusBarHidden {
return [self.navigationController prefersStatusBarHidden];
}
In the UINavigationController I do:
在UINavigationController中我做:
- (BOOL)prefersStatusBarHidden {
BOOL phoneLandscape = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && CGRectGetWidth(self.view.frame) > CGRectGetHeight(self.view.frame);
return _shouldHideStatusBar || phoneLandscape;
}
Where the _shouldHideStatusBar
ivar determines if the bar should be hidden or not.
_shouldHideStatusBar ivar确定是否应隐藏条形图。
Of course you need to set View controller-based status bar appearance
to YES
.
当然,您需要将基于View控制器的状态栏外观设置为YES。
Perfectly mimics the iOS 8 behavior and you can even animate the status bar using - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
.
完美模仿iOS 8行为,您甚至可以使用 - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation为状态栏设置动画。
The only problem is interactively showing and hiding the bar during view controller transitions. Not sure how to achieve that.
唯一的问题是在视图控制器转换期间以交互方式显示和隐藏条形图。不知道如何实现这一目标。
#2
Okay so after a bit of brainstorming as to how to hide the status bar without using the
好吧,经过一番头脑风暴后如何隐藏状态栏而不使用
[[UIApplication sharedApplication] setStatusBarHidden:YES];
so that it doesn't override the default behaviour of iOS 8, i researched a bit more and what i did was stretch the view so it takes up the entire screen (with the status bar height) and then i had to make sure that the
所以它不会覆盖iOS 8的默认行为,我研究了一下,我做的是拉伸视图,因此它占用整个屏幕(状态栏高度),然后我必须确保
self.view.window.windowLevel = UIWindowLevelStatusBar;
view window level was set so that it would essentially cover the status bar, this way whenever i enter the full screen mode my view goes on top of the status bar and whenever i leave it all i have to do is set the window level back to normal using
视图窗口级别已设置,以便它基本上覆盖状态栏,这样每当我进入全屏模式时,我的视图进入状态栏顶部,每当我离开它,我只需要将窗口级别设置回正常使用
self.view.window.windowLevel = UIWindowLevelNormal;
with these instructions i was able to emulate the full screen mode that i wanted without altering the actual behaviour of iOS 8 when changing to landscape and hiding the status bar.
通过这些说明,我可以模拟我想要的全屏模式,而无需在更改为横向和隐藏状态栏时更改iOS 8的实际行为。
#1
The solution I came up with:
我提出的解决方案:
I use a UINavigationController as the "super controller" of all my view controllers.
我使用UINavigationController作为所有视图控制器的“超级控制器”。
I subclassed the UINavigationController. In there I implement - (BOOL)prefersStatusBarHidden
and in my view controllers I call:
我将UINavigationController子类化。在那里我实现 - (BOOL)prefersStatusBarHidden并在我的视图控制器中调用:
- (BOOL)prefersStatusBarHidden {
return [self.navigationController prefersStatusBarHidden];
}
In the UINavigationController I do:
在UINavigationController中我做:
- (BOOL)prefersStatusBarHidden {
BOOL phoneLandscape = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && CGRectGetWidth(self.view.frame) > CGRectGetHeight(self.view.frame);
return _shouldHideStatusBar || phoneLandscape;
}
Where the _shouldHideStatusBar
ivar determines if the bar should be hidden or not.
_shouldHideStatusBar ivar确定是否应隐藏条形图。
Of course you need to set View controller-based status bar appearance
to YES
.
当然,您需要将基于View控制器的状态栏外观设置为YES。
Perfectly mimics the iOS 8 behavior and you can even animate the status bar using - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
.
完美模仿iOS 8行为,您甚至可以使用 - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation为状态栏设置动画。
The only problem is interactively showing and hiding the bar during view controller transitions. Not sure how to achieve that.
唯一的问题是在视图控制器转换期间以交互方式显示和隐藏条形图。不知道如何实现这一目标。
#2
Okay so after a bit of brainstorming as to how to hide the status bar without using the
好吧,经过一番头脑风暴后如何隐藏状态栏而不使用
[[UIApplication sharedApplication] setStatusBarHidden:YES];
so that it doesn't override the default behaviour of iOS 8, i researched a bit more and what i did was stretch the view so it takes up the entire screen (with the status bar height) and then i had to make sure that the
所以它不会覆盖iOS 8的默认行为,我研究了一下,我做的是拉伸视图,因此它占用整个屏幕(状态栏高度),然后我必须确保
self.view.window.windowLevel = UIWindowLevelStatusBar;
view window level was set so that it would essentially cover the status bar, this way whenever i enter the full screen mode my view goes on top of the status bar and whenever i leave it all i have to do is set the window level back to normal using
视图窗口级别已设置,以便它基本上覆盖状态栏,这样每当我进入全屏模式时,我的视图进入状态栏顶部,每当我离开它,我只需要将窗口级别设置回正常使用
self.view.window.windowLevel = UIWindowLevelNormal;
with these instructions i was able to emulate the full screen mode that i wanted without altering the actual behaviour of iOS 8 when changing to landscape and hiding the status bar.
通过这些说明,我可以模拟我想要的全屏模式,而无需在更改为横向和隐藏状态栏时更改iOS 8的实际行为。