Disappearing status bar at the top after MPMoviePlayerController is closed

♀尐吖头ヾ 提交于 2019-12-03 03:05:32

Maybe the animation from when the video view disappears is causing a timing issue with the status bar animation.

try delaying the statusBarHidden = NO call by a few seconds.

NSInteger delay = 3;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[UIApplication sharedApplication].statusBarHidden = NO;
});

You can just set the delay to be a float instead. So it would be

float delay = 0.1;

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
        [UIApplication sharedApplication].statusBarHidden = NO;
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
    });

I had the same problem and solved it by modifying richerd's code a bit. 0.1 second is acceptable imo. I also had to change the status bar style since it returned a BlackTranslucent bar style and the original was BlackOpaque style. But works fine now.

I've found that with the given solutions the content often disappears beneath the status bar. This approach fixes it.

Register for MPMoviePlayerWillExitFullscreenNotification

        [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillExitFullscreen:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:self.moviePlayer];

And then reset the status bar visibility AND remove and re-add the rootViewController from the main window, this will make sure that the bounds of the view are correct again.

- (void)moviePlayerWillExitFullscreen:(NSNotification *)notification {
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;

    id rootViewController = appDelegate.window.rootViewController;
    appDelegate.window.rootViewController = nil;
    appDelegate.window.rootViewController = rootViewController;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!