Skip to content

Instantly share code, notes, and snippets.

@hfossli
Created September 30, 2013 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hfossli/6767765 to your computer and use it in GitHub Desktop.
Save hfossli/6767765 to your computer and use it in GitHub Desktop.
UIApplication does not send notificaiton wether status bar is hidden or not. This class does!
#import <UIKit/UIKit.h>
extern NSString * const UIApplicationDidHideStatusBarNotification;
@interface IVYApplication : UIApplication
@end
#import "IVYApplication.h"
NSString * const UIApplicationDidHideStatusBarNotification = @"UIApplicationDidHideStatusBarNotification";
@interface IVYApplication ()
@property (nonatomic, assign) BOOL isCheckingStatusBarDisplayChange;
@end
@implementation IVYApplication
- (id)init
{
self = [super init];
if (self)
{
}
return self;
}
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle
{
[self checkForStatusBarChangeBeforeAndAfterBlock:^{
[super setStatusBarStyle:statusBarStyle];
}];
}
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated
{
[self checkForStatusBarChangeBeforeAndAfterBlock:^{
[super setStatusBarStyle:statusBarStyle animated:animated];
}];
}
- (void)setStatusBarHidden:(BOOL)statusBarHidden
{
[self checkForStatusBarChangeBeforeAndAfterBlock:^{
[super setStatusBarHidden:statusBarHidden];
}];
}
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated
{
[self checkForStatusBarChangeBeforeAndAfterBlock:^{
[super setStatusBarHidden:hidden animated:animated];
}];
}
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
{
[self checkForStatusBarChangeBeforeAndAfterBlock:^{
[super setStatusBarHidden:hidden withAnimation:animation];
}];
}
- (void)checkForStatusBarChangeBeforeAndAfterBlock:(dispatch_block_t)block
{
if(self.isCheckingStatusBarDisplayChange)
{
return;
}
self.isCheckingStatusBarDisplayChange = YES;
BOOL wasHidden = self.statusBarHidden;
block();
BOOL isHidden = self.statusBarHidden;
self.isCheckingStatusBarDisplayChange = NO;
if(wasHidden != isHidden)
{
[self postStatusBarHideStatusNotification];
}
}
- (void)postStatusBarHideStatusNotification
{
NSNotification *notifaction = [NSNotification notificationWithName:UIApplicationDidHideStatusBarNotification object:self];
[[NSNotificationCenter defaultCenter] postNotification:notifaction];
}
@end
#import <UIKit/UIKit.h>
#import "IVYApplication.h"
#import "IVYAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv,
NSStringFromClass([IVYApplication class]),
NSStringFromClass([IVYAppDelegate class]));
}
}
@slangley
Copy link

This only works for explicit calls to setStatusBarHidden, etc. It does not get fired for the UIViewController childViewControllerForStatusBarHidden mechanism of hiding the status bar.

@hfossli
Copy link
Author

hfossli commented Jun 24, 2014

@slangley Didn't think of that. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment