Disappearing status bar at the top after MPMoviePlayerController is closed

后端 未结 3 762
生来不讨喜
生来不讨喜 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: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;
    }
    

提交回复
热议问题