简体   繁体   中英

Retain original status bar appearance when using custom presentation controller

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.

Here's how I got around this:

- (UIStatusBarStyle)preferredStatusBarStyle {
  UIViewController *viewController = self.presentingViewController;
  while ([viewController childViewControllerForStatusBarStyle]) {
    viewController = [viewController childViewControllerForStatusBarStyle];
  }
  return [viewController preferredStatusBarStyle];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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