Skip to content

Instantly share code, notes, and snippets.

@martin-cotta
Created April 11, 2016 23:38
Show Gist options
  • Save martin-cotta/c73e806cd96938c5f1797ef85de2ab81 to your computer and use it in GitHub Desktop.
Save martin-cotta/c73e806cd96938c5f1797ef85de2ab81 to your computer and use it in GitHub Desktop.
Hack to fix navigation bar position/height on iOS 8 after closing fullscreen video
// on a portrait only app, when a video player is launched from a WebView
// and the user turn the phone into landscape and then closes the player,
// the navigation bar slips under the status bar
@property (nonatomic, strong) id observer;
- (instancetype)init {
@weakify(self);
NSString *name = @"UIWindowDidRotateNotification";
void(^block)(NSNotification * _Nonnull note) = ^void(NSNotification * _Nonnull note) {
@strongify(self);
if([note.userInfo[@"UIWindowOldOrientationUserInfoKey"] intValue] >= 3) { // old orientation was landscape
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
};
// or
NSString *name = UIDeviceOrientationDidChangeNotification;
void(^block)(NSNotification * _Nonnull note) = ^void(NSNotification * _Nonnull note) {
@strongify(self);
self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 64);
};
// add observer for notification
_observer = [[NSNotificationCenter defaultCenter] addObserverForName:name object:nil queue:nil usingBlock:block];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:_observer];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment