Created
July 10, 2016 05:53
-
-
Save b3ll/827929e4e0063797d1df9179bc51b65c to your computer and use it in GitHub Desktop.
Getting access to _statusBarWindow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.m | |
// StatusBarWindow | |
// | |
// Created by Adam Bell on 7/9/16. | |
// Copyright © 2016 Adam Bell. All rights reserved. | |
// | |
#import "AppDelegate.h" | |
#import <objc/runtime.h> | |
static UIWindow *_statusBarWindow = nil; | |
@interface UIWindow (StatusBarWindowPls) | |
- (instancetype)initWithFrame_swizzled:(CGRect)frame; | |
@end | |
@implementation UIWindow (StatusBarWindowPls) | |
- (instancetype)initWithFrame_swizzled:(CGRect)frame | |
{ | |
if (!(self = [self initWithFrame_swizzled:frame])) { | |
return nil; | |
} | |
// Status Bar Window's Class is UIStatusBarWindow | |
if ([NSStringFromClass([self class]) hasPrefix:@"UIS"]) { | |
_statusBarWindow = self; | |
} | |
return self; | |
} | |
@end | |
@interface UIApplication (StatusBarWindowPls) | |
+ (UIWindow *)sharedStatusBarWindow; | |
@end | |
@implementation UIApplication (StatusBarWindowPls) | |
+ (void)load | |
{ | |
Method original, swizzled; | |
original = class_getInstanceMethod([UIWindow class], @selector(initWithFrame:)); | |
swizzled = class_getInstanceMethod([UIWindow class], @selector(initWithFrame_swizzled:)); | |
method_exchangeImplementations(original, swizzled); | |
} | |
+ (UIWindow *)sharedStatusBarWindow | |
{ | |
return _statusBarWindow; | |
} | |
@end | |
@interface AppDelegate () | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// Override point for customization after application launch. | |
// Tada. | |
NSLog(@"%@", [UIApplication sharedStatusBarWindow]); | |
return YES; | |
} | |
@end | |
// Output: 2016-07-09 22:53:22.735 StatusBarWindow[19190:1310893] <UIStatusBarWindow: 0x7fd198e49a30; frame = (0 0; 414 736); opaque = NO; gestureRecognizers = <NSArray: 0x7fd198e134d0>; layer = <UIWindowLayer: 0x7fd198e26830>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment