[英]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.