0
votes

I know this question has been asked several times and the solutions I have seen have been very helpful. But since i have 2 conflicting requirements, I am a little stranded and hoping to find some help.

So here are the requirements:

  1. We have multiple View controllers out of which only one needs to be full screen (without status bar on the top).
  2. The other view controllers need to show a black status bar with a dark gray navigation bar

The First View controller is embedded in a navigation controller.

As recommended in some of the other posts, I did the following

  1. Set UIViewControllerBasedStatusBarAppearance to NO
  2. Added this code in app delegate

    CGRect frame = [[UIScreen mainScreen] bounds];

    self.window.frame = CGRectMake(0,20,frame.size.width, frame.size.height-20);

    self.window.bounds = self.window.frame;

It works fine if I only stay in those View controllers that have the status bar.

The moment I open the FULL screen view controller, that VC is cut off on the top as shown here.

enter image description here

Additionally when I come back to the Main view controller, now thats shifted up as well and the title bar is where the status bar was showing.

enter image description here I have tried to push the views back down by resetting the view.frame and requesting layout but it doesnt take effect.

Any suggestions on how to resolve this?

1

1 Answers

0
votes

Don't change self.window.bounds in app delegate. Instead, in your view controllers try something like this:

-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES/NO animated:YES];
    [self setNeedsStatusBarAppearanceUpdate]; // For showing/hiding status bar
    [super viewWillAppear:animated];
}

- (BOOL)prefersStatusBarHidden {
    return YES/NO;
}

You will have different frames for the view in ViewDidLoad according to whether status bar and navigation bar are there.