Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c MPMoviePlayerController关闭后顶部的状态栏消失_Objective C_Mpmovieplayercontroller_Statusbar - Fatal编程技术网

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

Objective c MPMoviePlayerController关闭后顶部的状态栏消失,objective-c,mpmovieplayercontroller,statusbar,Objective C,Mpmovieplayercontroller,Statusbar,我的iPhone应用程序有一个有趣的小问题。我有一个带有表格的视图,当单击每个单元格时,会全屏播放视频,然后当您按“完成”时,视频停止并返回到表格视图。唯一的问题是,当您在视频加载的前2或3秒内按done时,当视图返回到table视图时,屏幕顶部显示时间和电池电量等信息的条不再存在,它只是一个空白。但是如果在开始几秒钟后按done,那么当您返回到table视图时,一切都绝对正常!我完全不知道为什么会发生这种情况,我在互联网上发现的唯一一件事是,这是一个和我有着几乎完全相同问题的人: 这使我尝试

我的iPhone应用程序有一个有趣的小问题。我有一个带有表格的视图,当单击每个单元格时,会全屏播放视频,然后当您按“完成”时,视频停止并返回到表格视图。唯一的问题是,当您在视频加载的前2或3秒内按done时,当视图返回到table视图时,屏幕顶部显示时间和电池电量等信息的条不再存在,它只是一个空白。但是如果在开始几秒钟后按done,那么当您返回到table视图时,一切都绝对正常!我完全不知道为什么会发生这种情况,我在互联网上发现的唯一一件事是,这是一个和我有着几乎完全相同问题的人:

这使我尝试使用:

[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;
如果有人能解释一下这种情况,我将非常感激,因为这是非常令人沮丧的

谢谢


Matt

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

尝试将statusBarHidden=无呼叫延迟几秒钟

NSInteger delay = 3;

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

您可以将延迟设置为浮点值。是的

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秒是可以接受的。我还必须更改状态栏样式,因为它返回了一个黑色半透明条样式,而原来的是黑色不透明样式。但现在工作正常。

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

注册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;
}

谢谢,这确实有效,但它成功延迟的最短时间似乎是1秒,这有点太长了。如果这是我唯一可以修复它的方法,那么它就可以了,但最好是在视图加载时立即显示,而不是1秒后