2

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]; 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. 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

-(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.

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
Paul Crono
  • 61
  • 1
  • 6
  • I think this is a known bug if I'm not mistaken. Info: http://blog.motioninmotion.tv/fixing-the-ios-7-navigation-bar-overlap-problem < (not sure if that is your issue) – l'L'l Apr 12 '14 at 15:45
  • As you transition to the new view controller, do you want to see the status bar slide up, while the navigation bar stays in place (as opposed to never seeing the status bar in the new controller)? – rdelmar Apr 12 '14 at 16:25

3 Answers3

1

There's no clean way to prevent UINavigationController from adjusting the height of its navigation bar. I describe the behavior in detail in this SO answer.

The only workaround currently is that UINavigationController only performs those height adjustments whenever it's view's bounds matches the bounds of the window, i.e., if the navigation controller's view fills the screen. If the view's bounds are off, even by a pixel, it will default to a standard 44 point high navigation bar.

Karah's answer above is incorrect. UIViewControllerBasedStatusBarAppearance is used to determine the color and visibility of the status bar. It has nothing to do with UINavigationController's nav bar height logic.

Community
  • 1
  • 1
jaredsinclair
  • 12,687
  • 5
  • 35
  • 56
0

There no clear way to do this, but you can set this thing by using following code in 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];
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
-1

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.

joels
  • 1,292
  • 15
  • 21
  • But the person wants to hide the status bar and maintain the navigation bar position. Just disabling the option to not being controlled by individual view controllers doesn't help. – andromedainiative Dec 29 '17 at 08:39