gpt4 book ai didi

iphone - navigationBar 和 MPMoviePlayerController 的异常行为。 iOS 中的错误还是我的错误?

转载 作者:可可西里 更新时间:2023-11-01 03:38:53 24 4
gpt4 key购买 nike

我有一个 MPMoviePlayerController 对象,可以纵向或横向全屏播放视频。如果我在播放视频时旋转方向,并在视频开始播放并且视频状态栏可见后几秒钟内进行旋转,那么当视频结束时我的导航栏是完美的。但是,如果我等到视频状态栏在视频播放几秒钟后消失,然后旋转方向,当视频结束时,我的 navigationBar 会部分隐藏在状态栏后面,就像向上推一样。

你见过这样的东西吗?

我能够轻松地重现此错误。我创建了一个新的 Single View App,并简单地添加了一个按钮和一个导航栏。如果我在播放视频时旋转方向,点击以启用全屏并且视频状态栏仍然可见,当视频结束时,一切都很好。但是,如果我在视频状态栏消失后等待旋转,当我旋转并且视频结束时,导航栏位于状态栏下方。看图:

iPhone Image

这是我使用的简单代码:

- (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];
}

这是我目前所处的位置,下面给出了建议。我一定是出了什么问题,因为不幸的是我仍然有同样的问题。

这是方法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 中,我解决了这个问题,将这段代码放在我的 View Controller 中。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

棘手的错误,棘手的修复。

关于iphone - navigationBar 和 MPMoviePlayerController 的异常行为。 iOS 中的错误还是我的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com