简体   繁体   English

使用自定义呈现控制器时保留原始状态栏外观

[英]Retain original status bar appearance when using custom presentation controller

I present a navigation controller from controller contained in navigation controller using custom UIPresentationController .我使用自定义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.我玩过modalPresentationStyle但我无法用它实现任何目标,在我的情况下唯一合理的值是UIModalPresentationCustom ,否则没有任何效果或变得非常奇怪。

I do not implement preferredStatusBarStyle anywhere because on iOS 9 navigation controller picks the right one from navigation bar style.我没有在任何地方实现preferredStatusBarStyle因为在 iOS 9 导航控制器从导航栏样式中选择正确的。

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. Transition 本身是半模态的,这意味着源控制器的某些部分保留在屏幕上。 This is why the UIPresentationController subclass implements shouldRemovePresentersView这就是UIPresentationController子类实现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.以下雷达:( https://openradar.appspot.com/22565293 )描述了这个问题,在私有方法的帮助下,我能够阻止呈现的控制器捕获状态栏外观。

- (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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “查看基于控制器的状态栏外观”= YES时隐藏ios状态栏 - Hide ios status bar when “View controller-based status bar appearance”=YES 覆盖基于视图控制器的状态栏外观 - Overriding view controller based status bar appearance 设置基于View控制器的状态栏外观= YES时,StatusBar不调用preferredStatusBarStyle - StatusBar ins't calling preferredStatusBarStyle when setting View controller-based status bar appearance = YES 如何检索当前控制状态栏外观的视图控制器? - How to retrieve view controller that currently controls status bar appearance? 使用WKWebView时的自定义状态栏颜色 - Custom Status Bar Color when using WKWebView 使用自定义模式演示处理通话中状态栏 - Handling In-Call Status Bar with Custom Modal Presentation 在XCode 8.2 / Swift 3.0中更改状态栏样式(否“查看基于控制器的状态栏外观”) - Change Status Bar style in XCode 8.2 / Swift 3.0 (No “View controller-based status bar appearance”) 自定义视图控制器演示导致导航栏反弹 - Custom view controller presentation causes the navigation bar to bounce 状态栏在模态演示中消失 - Status Bar Disappears on Modal Presentation (快速)状态栏外观UIImagePickerController - (Swift) status bar appearance UIImagePickerController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM