在 iOS8 上,以横向模式显示我的应用程序将隐藏状态栏,但在 iOS 7 上,状态栏显示在两个方向上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24329503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
On iOS8, displaying my app in landscape mode will hide the status bar but on iOS 7 the status bar is displayed on both orientations
提问by Tim Nuwin
I want the status bar to be displayed in both orientations in iOS 8; it's being displayed properly in iOS 7.
我希望状态栏在 iOS 8 中以两个方向显示;它在 iOS 7 中正确显示。
navigationController.isNavigationBarHidden
returns NO.
navigationController.isNavigationBarHidden
返回 NO。
Why is iOS 8 doing this?
为什么 iOS 8 会这样做?
回答by Jageen
Try this
尝试这个
Add below code in didRotateFromInterfaceOrientation
在下面添加代码 didRotateFromInterfaceOrientation
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
EDIT
NO NEED TO WRITE CODE IN ALL VIEW CONTROLLER
Set View controller-based status bar appearance
to NO
in plist
and add below code in
root view controller's viewDidLoad
编辑
无需在所有视图控制器中编写代码
设置View controller-based status bar appearance
为NO
inplist
并在根视图控制器中添加以下代码viewDidLoad
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
Demo project
https://www.dropbox.com/s/uumneidk4wom5md/demoStatusBar.zip?dl=0
演示项目
https://www.dropbox.com/s/uumneidk4wom5md/demoStatusBar.zip?dl=0
回答by Vidhi
To display status bar in landscape mode in ios 8, try following method
要在 ios 8 中以横向模式显示状态栏,请尝试以下方法
- (BOOL)prefersStatusBarHidden {
return NO;
}
Swift version
迅捷版
override func prefersStatusBarHidden() -> Bool {
return false
}
Swift 3, Xcode 8, iOS 10, /* ViewController.swift */
Swift 3, Xcode 8, iOS 10, /* ViewController.swift */
override var prefersStatusBarHidden: Bool {
return false
}
回答by Mustafa
Jageen's solution is probably the best, with just one minor change i.e. instead of using viewDidLoad
, it's better to use application:didFinishLaunchingWithOptions:
.
Jageen 的解决方案可能是最好的,只有一个小改动,即不是使用viewDidLoad
,而是使用application:didFinishLaunchingWithOptions:
.
It's basically a two step process:
它基本上是一个两步过程:
1). Set "View controller-based status bar appearance" to NO, in your project's Info.plist file.
1)。在项目的 Info.plist 文件中将“基于控制器的状态栏外观”设置为否。
2). Force the status bar hidden status to NO, in application:didFinishLaunchingWithOptions:
, using the following code:
2)。application:didFinishLaunchingWithOptions:
使用以下代码强制状态栏隐藏状态为 NO, in :
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
And, voila!
而且,瞧!
Note:It's important to use both the setStatusBarHidden:withAnimation
statements above, to force the status bar hidden state.
注意:使用setStatusBarHidden:withAnimation
上面的两个语句来强制状态栏隐藏状态很重要。
回答by Ganesh Guturi
It's not an issue but a feature of an iOS 8. The status bar will be hidden in landscape mode in iOS 8, even Apple's applications also having same behaviour.
这不是问题,而是 iOS 8 的一个特性。状态栏将在 iOS 8 中以横向模式隐藏,即使 Apple 的应用程序也具有相同的行为。
回答by serg_ov
I had the same issue! Fixed by addicting this to viewDidLoad
我遇到过同样的问题!通过将其添加到 viewDidLoad 来修复
[self setNeedsStatusBarAppearanceUpdate];
And this to implementation itself
这对实现本身
-(BOOL)prefersStatusBarHidden{
return NO;
}
回答by DBD
They are keeping us gainfully employed by giving us more work.
他们通过给我们更多的工作来让我们有报酬地就业。
or...
或者...
They've made other changes which cause bits to take up more space than they used to. With iOS 7 and the advent of things like the "Top Layout Bar Guide", the easy availability of the status bar in the swipe down screen, reclaiming the status bar space to be usable and other little hints many people predicted the status bar might be getting phased out as a standard part of the UI.
他们进行了其他更改,导致位占用比以前更多的空间。随着 iOS 7 和“顶部布局栏指南”的出现,状态栏在向下滑动屏幕中的轻松可用性,回收状态栏空间以供使用以及许多人预测状态栏可能会出现的其他小提示作为 UI 的标准部分逐渐被淘汰。
There is also quite a bit of buzz about new device sizes due to the changes they've made in iOS 8 trying to make it easier to code for a bunch of different sizes.
由于新设备尺寸在 iOS 8 中所做的更改,它们试图让编写大量不同尺寸的代码变得更容易,因此也有很多关于新设备尺寸的讨论。
It's pure speculation, but I don't think they landscape status bar will return in iOS 8.
这纯粹是猜测,但我认为它们的横向状态栏不会在 iOS 8 中恢复。
回答by Vyacheslav
Swift 3
斯威夫特 3
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.setStatusBarHidden(true, with: .none)
UIApplication.shared.setStatusBarHidden(false, with: .none)
///
}
and add inside Info.plist
this:
并在其中添加Info.plist
:
UIViewControllerBasedStatusBarAppearance
boolean value NO
UIViewControllerBasedStatusBarAppearance
布尔值 NO
回答by BennyTheNerd
Swift 3(As of June 2, 2017)
Swift 3 (截至 2017 年 6 月 2 日)
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear()
self.setNeedsStatusBarAppearanceUpdate()
}
override var prefersStatusBarHidden : Bool {
return false
}
回答by StackRunner
We fixed it by following the above steps and making sure that landscape left and right are both enabled.
我们按照上述步骤修复了它,并确保启用左右横向。
Under Project/Target/Deployment Info
在项目/目标/部署信息下
回答by Ben Ritter
We solved this by forcing an orientation change unseen by the user. In the first view controller that loads, add:
我们通过强制用户看不见的方向改变来解决这个问题。在加载的第一个视图控制器中,添加:
- (void)viewWillAppear:(BOOL)animated
{
NSNumber *orientationLeft = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
NSNumber *orientationRight = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationLeft forKey:@"orientation"];
[[UIDevice currentDevice] setValue:orientationRight forKey:@"orientation"];
}