MPMoviePlayerController关闭后,顶部消失的状态栏

时间:2011-08-24 13:28:07

标签: objective-c mpmovieplayercontroller statusbar

我的iPhone应用程序有一个有趣的小问题。我有一个带有桌子的视图,每个单元格在单击时播放全屏视频,然后当您按完时,视频停止并返回到表格视图。唯一的问题是,当您在视频加载的前2或3秒内完成按下时,当视图返回到表视图时,屏幕顶部的条形图将告知时间和电池强度等不再那里,它只是一个白色的空间。但是如果你在前几秒后按完了,那么当你回到表视图时,一切都绝对没问题!我完全不知道为什么会这样,我在互联网上找到的唯一一件事就是这个和我差不多完全一样的人:

http://www.iphonedevsdk.com/forum/iphone-sdk-development/53020-disappearing-status-bar.html

这导致我尝试使用:

[UIApplication sharedApplication].statusBarHidden = NO;

然而,这也没有任何意义。

点击视频时执行的代码:

NSString *path = [[NSBundle mainBundle] pathForResource:currentTitle ofType:@"m4v"];
NSURL *url = [NSURL fileURLWithPath:path];
movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
[movieController setControlStyle:MPMovieControlStyleFullscreen];
[movieController setFullscreen:YES];
movieController.view.frame = self.view.bounds;
[self.view addSubview:movieController.view];

[[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

在视频完成或用户点击完成时执行的代码是:

NSLog(@"movieController moviePlayBackDidFinish");
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[movieController setFullscreen:NO animated:NO];
[movieController.view removeFromSuperview];

[movieController release];

LiveEventsView *liveEventsView = [[LiveEventsView alloc] initWithNibName:@"LiveEventsView" bundle:nil];
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
UIView *newView = liveEventsView.view;
newView.frame = CGRectMake(0, 20, 320, 460);
[currentView removeFromSuperview];
[theWindow addSubview:newView];
[UIApplication sharedApplication].statusBarHidden = NO;

如果有人能够对这种情况有所了解,我将非常感激,因为它非常令人沮丧!

谢谢,

马特

3 个答案:

答案 0 :(得分:6)

可能视频视图消失时的动画导致状态栏动画出现计时问题。

尝试延迟statusBarHidden = NO呼叫几秒钟。

NSInteger delay = 3;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[UIApplication sharedApplication].statusBarHidden = NO;
});

答案 1 :(得分:6)

您可以将延迟设置为浮点数。所以它会是

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;
    });

我遇到了同样的问题,并通过修改richerd的代码解决了这个问题。 0.1秒是可以接受的。我还必须更改状态栏样式,因为它返回了BlackTranslucent栏样式,而原始样式是BlackOpaque样式。但现在工作正常。

答案 2 :(得分:3)

我发现使用给定的解决方案,内容通常会在状态栏下方消失。这种方法解决了这个问题。

注册MPMoviePlayerWillExitFullscreenNotification

        [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillExitFullscreen:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:self.moviePlayer];

然后重置状态栏可见性并从主窗口中删除并重新添加rootViewController,这将确保视图的边界再次正确。

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