2

I present a navigation controller from controller contained in navigation controller using custom UIPresentationController.

My problem is that I cannot retain original status bar appearance. I don't want to give control over status bar to newly presented modal, instead I want to leave it up to source controller. How can I do this?

I played with modalPresentationStyle but I was not able to achieve anything with it, the only reasonable value in my case is UIModalPresentationCustom, otherwise nothing works or gets pretty weird.

I do not implement preferredStatusBarStyle anywhere because on iOS 9 navigation controller picks the right one from navigation bar style.

self.stackTransitionDelegate = [[StackTransitionDelegate alloc] init];

controller.modalPresentationStyle = UIModalPresentationCustom;
controller.transitioningDelegate = self.stackTransitionDelegate;

[self.presentationContext presentViewController:controller animated:YES completion:nil];

Transition itself is half modal, that means that some part of source controller remains on screen. This is why the UIPresentationController subclass implements shouldRemovePresentersView

- (BOOL)shouldPresentInFullscreen {
    return NO;
}

Update:

The following radar: (https://openradar.appspot.com/22565293) describes the problem and with help of private method I am able to prevent presented controller from capturing status bar appearance.

- (BOOL)_shouldChangeStatusBarViewController {
    if([self.presentedViewController isBeingPresented]) {
        return NO;
    }
    return YES;
}

I wonder if there is any official way of achieving the same.

pronebird
  • 12,068
  • 5
  • 54
  • 82

1 Answers1

1

Here's how I got around this:

- (UIStatusBarStyle)preferredStatusBarStyle {
  UIViewController *viewController = self.presentingViewController;
  while ([viewController childViewControllerForStatusBarStyle]) {
    viewController = [viewController childViewControllerForStatusBarStyle];
  }
  return [viewController preferredStatusBarStyle];
}
bogardon
  • 896
  • 2
  • 10
  • 22