Content drift issue after watching video in iOS 8
I have a TabBarController, InterfaceOrientations - UIInterfaceOrientationMaskPortrait is supported. The navigation bar moves below the status bar when I start watching a video from one of the tabs, rotate the device to landscape, and then exit full screen mode. Why is this happening and how can I fix it?
+3
source to share
2 answers
This is kind of a hack but works in my view controller contains a UIWebView and full screen videos start with <video> tags.
You will see the navigation bar twitch because it UIWindowDidBecomeHiddenNotification
is called after the full screen video window just disappears.
- (void)viewDidLoad
{
[super viewDidLoad];
// NOTE: I'm not sure, but MPMoviePlayerWillExitFullscreenNotification won't work
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeHidden:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)windowDidBecomeHidden:(NSNotification *)notification
{
UIView *navbar = self.navigationController.navigationBar;
CGRect barFrame = navbar.frame;
barFrame.origin.y = 20;
self.navigationController.navigationBar.frame = barFrame;
UIView *navbarBack = nil;
for (UIView *view in navbar.subviews) {
if ([NSStringFromClass([view class]) isEqual:@"_UINavigationBarBackground"]) {
navbarBack = view;
break;
}
}
CGRect backFrame = navbarBack.frame;
backFrame.origin.y = -20;
backFrame.size.height = 64;
navbarBack.frame = backFrame;
[navbar.superview setNeedsLayout];
}
UIView *navbarBack = [navbar.subviews bk_match:^BOOL(UIView *view) {
return [NSStringFromClass([view class]) isEqual:@"_UINavigationBarBackground"];
}];
+1
source to share