Disappearing status bar at the top after MPMoviePlayerController is closed

后端 未结 3 757
生来不讨喜
生来不讨喜 2021-02-06 03:23

Having an interesting little problem with my iPhone app. I have a view with a table and each cell, when clicked, plays a video fullscreen then when you press done, the video sto

相关标签:
3条回答
  • 2021-02-06 04:01

    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;
    });
    
    0 讨论(0)
  • 2021-02-06 04:25

    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;
    }
    
    0 讨论(0)
  • 2021-02-06 04:27

    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.

    0 讨论(0)
提交回复
热议问题