I have an MPMoviePlayerController object that plays full-screen video in portrait or landscape orientation. If I rotate the orientation during video playback and perform the rotation within a few seconds after the video starts playing, and the video status bar is displayed when the video ends, my navigation bar is perfect. But if I wait until the video status bar disappears a few seconds before the video plays, and then rotate the orientation when the video ends, my navigationBar partially hides behind the status bar, for example, is pressed up.
Have you ever seen something like this?
I can easily recreate this error. I created a new Single View application and just added a button and a navigation bar. If I rotate the orientation while playing a video, click to turn on the full screen mode and the video status bar is still visible when the video ends, everything is fine. But, if I wait to rotate after the disappearance of the video status bar, when I rotate and the video ends, the navigation bar is in the status bar. See Image:
IPhone image
Here is the simple code that I use:
- (void) playMovie { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"movie" ofType: @"mov"]]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(moviePlayBackDidFinish:) name: MPMoviePlayerPlaybackDidFinishNotification object: moviePlayer]; moviePlayer.controlStyle = MPMovieControlStyleDefault; moviePlayer.shouldAutoplay = YES; [self.view addSubview: moviePlayer.view]; [moviePlayer setFullscreen: YES animated: YES]; - (void) moviePlayBackDidFinish: (NSNotification *) notification MPMoviePlayerController *player = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerPlaybackDidFinishNotification object: player]; if ([player respondsToSelector: @selector(setFullscreen:animated:)]) { [player.view removeFromSuperview]; }
This is where I am now with the suggestions below. I must have something wrong, because, unfortunately, I still have the same problem.
Here is the onPlayerWillExitFullScreen method
UIView *view = [[[UIApplication sharedApplication] delegate].window.subviews lastObject]; if (view) { [view removeFromSuperview]; [[[UIApplication sharedApplication] delegate].window addSubview:view]; } MPMoviePlayerController *player = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerWillExitFullscreenNotification object: player];
and here is my current playMovie method:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"movie" ofType: @"mov"]]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(moviePlayBackDidFinish:) name: MPMoviePlayerPlaybackDidFinishNotification object: moviePlayer]; [[NSNotificationCenter defaultCenter]addObserver: self selector: @selector(onPlayerWillExitFullScreen:) name: MPMoviePlayerWillExitFullscreenNotification object: self.moviePlayer]; moviePlayer.controlStyle = MPMovieControlStyleDefault; moviePlayer.shouldAutoplay = YES; [self.view addSubview: moviePlayer.view]; [moviePlayer setFullscreen: YES animated: YES];