gpt4 book ai didi

ios - 在 iPhone X 上,分别控制显示/隐藏导航栏和状态栏

转载 作者:行者123 更新时间:2023-12-01 19:46:35 24 4
gpt4 key购买 nike

我想分别控制显示和隐藏NavigationBarStatusBar或我的应用程序中的每个屏幕。

iPhone6 , iPhone7 iPhone8 , 没关系。

enter image description here

但是在 iPhoneX , 当 NavigationBar显示,StatusBar即使 prefersStatusBarHidden 也一起显示设置为YES。

NavigationBar 的高度比 StatusBar

enter image description here

如果你能告诉我一个好的解决方案,我将不胜感激。

谢谢你。

我的代码如下所示,

FirstViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];

self.view.backgroundColor = UIColor.yellowColor;

self.navigationController.navigationBarHidden = YES;
} }

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

self.navigationController.navigationBarHidden = YES;
}

- (void)touchUpButton:(UIButton *)button
{
SecondViewController *vc = [[SecondViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}

- (BOOL)prefersStatusBarHidden
{
return YES;
}

SecondViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];

self.navigationController.navigationBarHidden = NO;
self.navigationItem.title = @"SecondView";

self.view.backgroundColor = UIColor.cyanColor;
}

- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden = NO;
}

- (BOOL)prefersStatusBarHidden
{
return YES;
}

最佳答案

这是 iPhone X 的预期行为,您无法阻止它。在其他 iPhone 上,当您显示导航栏且没有状态栏时,导航栏导航栏会向上移动到屏幕顶部。但是在 iPhone X 上它不能这样做,因为“缺口”会切入它,你会失去部分标题。因此,当显示导航栏时,始终显示状态栏。

这就是为什么在 iPhone X 的 HIG 中这样说的原因之一:

If your app currently hides the status bar, reconsider that decision for iPhone X. The display height on iPhone provides more vertical space for content than the displays of 4.7" iPhones, and the status bar occupies an area of the screen your app probably won't fully utilize. The status bar also displays information people find useful. It should only be hidden in exchange for added value.



作为额外的信息,如果您在 iPhone X 上将显示屏的顶部和底部设置为黑色(特别是为了隐藏它的圆角和“缺口”),那么这是让您的应用程序被 Apple 拒绝的快速方法。再次在 iPhone X 的 HIG 中,它说:

Don't mask or call special attention to key display features. Don't attempt to hide the device's rounded corners, sensor housing, or indicator for accessing the Home screen by placing black bars at the top and bottom of the screen. Don't use visual adornments like brackets, bezels, shapes, or instructional text to call special attention to these areas, either.



虽然其中大部分只是指南,但 Apple 对此非常热衷,并且几乎总是会因为它而拒绝应用程序。

关于ios - 在 iPhone X 上,分别控制显示/隐藏导航栏和状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48207378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com