简体   繁体   English

隐藏状态栏和导航栏位置

[英]Hiding status bar and navigation bar position

I have one issue which i can't handle with it. 我有一个我无法处理的问题。 I have two view controllers and I use [[UIApplication sharedApplication] setStatusBarHidden:isHidden withAnimation:UIStatusBarAnimationSlide]; 我有两个视图控制器,并且使用[[UIApplication sharedApplication] setStatusBarHidden:isHidden withAnimation:UIStatusBarAnimationSlide]; to show/hide status bar. 显示/隐藏状态栏。 All works pefect but I need one thing: everything is embed in navigation controller and after hiding status bar navigation bar is moving up for 20 px. 一切正常,但我需要做一件事:一切都嵌入到导航控制器中,隐藏状态栏后,导航栏向上移动20 px。 How can I remove this effect? 如何消除这种影响? With or without status bar i want navigation bar at the same place in every time. 有状态栏或无状态栏,我每次都希望导航栏位于同一位置。

Edit1: I've already done this Edit1:我已经做到了

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.layer.transform = CATransform3DIdentity;
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    self.navigationController.navigationBar.layer.transform = CATransform3DMakeTranslation(0, 20, 0);
}

It works but animation is terrible and i need something better. 它可以工作,但是动画太糟糕了,我需要更好的东西。

There's no clean way to prevent UINavigationController from adjusting the height of its navigation bar. 没有干净的方法可以防止UINavigationController调整其导航栏的高度。 I describe the behavior in detail in this SO answer . 我在这个SO答案中详细描述了行为。

The only workaround currently is that UINavigationController only performs those height adjustments whenever it's view's bounds matches the bounds of the window, ie, if the navigation controller's view fills the screen. 当前唯一的解决方法是,UINavigationController仅在视图的边界与窗口的边界匹配时(即,如果导航控制器的视图占满屏幕),才执行这些高度调整。 If the view's bounds are off, even by a pixel, it will default to a standard 44 point high navigation bar. 如果视图的边界已关闭,即使只有一个像素,它将默认为标准的44点高的导航栏。

Karah's answer above is incorrect. 卡拉的上述答案不正确。 UIViewControllerBasedStatusBarAppearance is used to determine the color and visibility of the status bar. UIViewControllerBasedStatusBarAppearance用于确定状态栏的颜色和可见性。 It has nothing to do with UINavigationController's nav bar height logic. 它与UINavigationController的导航栏高度逻辑无关。

There no clear way to do this, but you can set this thing by using following code in ViewDidLoad : 没有明确的方法可以执行此操作,但是您可以通过在ViewDidLoad中使用以下代码来设置此内容:

    CGRect statusFrame = CGRectMake(0.0, -20.0, 1024, 20);
    UIView* statusBar = [[UIView alloc] initWithFrame:statusFrame];
    statusBar.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBar];
    [statusBar release];

When your status bar is hidden, the navigation bar automatically moves up to make up for the space. 隐藏状态栏时,导航栏会自动向上移动以弥补空间。

If you set UIViewControllerBasedStatusBarAppearance to YES , it should stop that behaviour. 如果将UIViewControllerBasedStatusBarAppearance设置为YES ,则应停止该行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM