1
votes

I want to hide/show status bar when user taps a button. Here is how i do it:

// Hide
[[UIApplication sharedApplication] setStatusBarHidden:YES
                                   withAnimation:UIStatusBarAnimationFade];
// Show
[[UIApplication sharedApplication] setStatusBarHidden:NO
                                   withAnimation:UIStatusBarAnimationFade];

This brakes UI layout, because view is moved up. I selected all Extend Edges options, but it didn't help. enter image description here

I discovered that layout changes because of view height:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    NSLog(@"%@", NSStringFromCGRect(self.navigationController.view.frame));
}

It logs:

{{0, 0}, {320, 568}} - when Status Bar is hidden.

{{0, 0}, {320, 588}} - when it is shown.

The question is how to prevent view frame change when Status Bar is being shown or hidden.

2

2 Answers

1
votes

This is an issue in iOS 8. You can restore the old behavior by overriding the following

 -(BOOL)prefersStatusBarHidden {
   return YES;
  }
0
votes

My Navigation Controller was embedded in the other view, which one was aligned to the Top Layout Guide. That was the problem.