Skip to content

Instantly share code, notes, and snippets.

@pronebird
Created April 27, 2016 15:12
Show Gist options
  • Save pronebird/1aa5db9fe0c7f3b760d337adcb4bbd80 to your computer and use it in GitHub Desktop.
Save pronebird/1aa5db9fe0c7f3b760d337adcb4bbd80 to your computer and use it in GitHub Desktop.
Keep presenting controller in charge of status bar appearance during modal presentation. Useful on modal presentations that only partially cover the window.
//
// BasePresentationController.h
//
// Created by pronebird on 4/27/16.
// Copyright © 2016 Andrey Mikhaylov. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface BasePresentationController : UIPresentationController
/**
* Override this property and return NO if you wish presenting controller
* to remain in charge of status bar appearance.
* Default: YES
*/
@property (nonatomic, readonly) BOOL presentedControllerCapturesStatusBarAppearance;
@end
//
// BasePresentationController.m
//
// Created by pronebird on 4/27/16.
// Copyright © 2016 Andrey Mikhaylov. All rights reserved.
//
#import "BasePresentationController.h"
@interface UIPresentationController ()
- (BOOL)_shouldChangeStatusBarViewController;
@end
@implementation BasePresentationController
- (BOOL)presentedControllerCapturesStatusBarAppearance {
return YES;
}
/*
@TODO: This is a private API to prevent presented controller
from becoming responsible for statusbar appearance. This should be fixed
in official way.
*/
- (BOOL)_shouldChangeStatusBarViewController {
if([self presentedControllerCapturesStatusBarAppearance]) {
return [super _shouldChangeStatusBarViewController];
}
if(self.presentedViewController.modalPresentationCapturesStatusBarAppearance) {
NSLog(@"%@ implements presentedControllerCapturesStatusBarAppearance and returns YES, however presented controller has modalPresentationCapturesStatusBarAppearance set to YES. Make sure modalPresentationCapturesStatusBarAppearance is set to NO otherwise presenting controller won't remain in charge of status bar appearance.", NSStringFromClass([self class]));
}
if([self.presentedViewController isBeingPresented]) {
return NO;
}
return YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment