【问题标题】:Disappearing status bar at the top after MPMoviePlayerController is closedMPMoviePlayerController 关闭后顶部状态栏消失
【发布时间】:2011-11-02 19:44:44
【问题描述】:

我的 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;

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

谢谢,

马特

【问题讨论】:

    标签: objective-c mpmovieplayercontroller statusbar


    【解决方案1】:

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

    尝试将 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 秒,这有点太长了。如果这是我可以修复它的唯一方法,那么它会这样做,但最好它会在视图加载后立即出现,而不是 1 秒后
    【解决方案2】:

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

    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 样式。但现在工作正常。

    【讨论】:

      【解决方案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;
      }
      

      【讨论】:

        猜你喜欢
        • 2013-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-08
        • 1970-01-01
        • 1970-01-01
        • 2015-07-17
        相关资源
        最近更新 更多