navigationBar和MPMoviePlayerController非常奇怪的行为。 iOS中的错误或我的错误? [英] Extremely weird behavior of navigationBar and MPMoviePlayerController. Bug in iOS or my error?
问题描述
我有一个 MPMoviePlayerController
对象,可以纵向或横向播放全屏视频。如果我在视频播放时旋转方向并在视频开始播放后几秒钟内完成旋转并且视频状态栏可见,则当视频结束时我的导航栏是完美的。但是,如果我等到视频状态栏消失几秒钟进入视频播放然后旋转方向,当视频结束时我的 navigationBar
部分隐藏在状态栏后面,如推高了。
I have a MPMoviePlayerController
object that plays a video fullscreen in either portrait or landscape. If I rotate orientation while the video is playing and do the rotation within a few seconds after the video starts playing and the video status bar is visible, when the video ends my navigation bar is perfect. But if I wait until the video status bar disappears a few seconds into the video playing and then rotate orientation, when the video ends my navigationBar
is partially hidden behind the status bar, like pushed up.
你见过这样的东西吗?
我能够轻松地重新创建这个bug。我创建了一个新的单视图应用程序,只需添加一个按钮和一个导航栏。如果我在播放视频时旋转方向,点击以启用全屏,视频状态栏仍然可见,视频播放完毕后,一切都很好。但是,如果我在视频状态栏消失后等待旋转,当我旋转并且视频结束时,navigationBar位于状态栏下。见图:
I am able to recreate this bug easily. I created a new Single View App and simply added a button and a navigation bar. If I rotate orientation while video is playing, tap to enable fullscreen and the video status bar is still visible, when the video finishes, all is good. But, if I wait to rotate after the video status bar disappears, when I rotate and the video finishes, the navigationBar is under the status bar. See image:
以下是我使用的简单代码:
Here is the simple code I am using:
- (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];
}
以下是我目前所处的建议。我一定有问题,因为不幸的是我仍然遇到同样的问题。
Here is where I am currently at with the suggestions given below. I must have something wrong because unfortunately I still have the same problem.
这是方法 onPlayerWillExitFullScreen
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];
这是我当前的 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];
[[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];
推荐答案
好的,所以我发现了这个怪异的错误我的应用程序首先在UIWebView中,然后在MPMoviePlayerController中,我解决了这个问题,将此代码放在我的视图控制器中。
Ok, so I found this freaking same bug all over my app first in a UIWebView then in a MPMoviePlayerController, I solved this placing this code in my view controller.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
棘手的错误,棘手的修复。
Tricky bugs, tricky fixes.
这篇关于navigationBar和MPMoviePlayerController非常奇怪的行为。 iOS中的错误或我的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!