我有包含几页的 tabBarViewController 和一个 loginViewController。我使用 [window addSubView:] 添加视图。
当我需要播放全屏视频时,我必须删除窗口中的所有视图才能显示视频,否则它只是一个黑屏。当视频停止/完成/退出全屏时,我必须手动将子视图再次添加回窗口。
我知道这是一种错误的做法。如果我不这样做,当视频切换到全屏时,它将显示在根窗口视图中,在其他视图的后面。
请给一些建议。谢谢你。
下面是我的代码:
-(void)playMovie:(NSString *)urlStr{
NSURL *fileURL = [NSURL URLWithString:urlStr];
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
player.scalingMode = MPMovieScalingModeAspectFit;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[appDelegate loginViewController].view removeFromSuperview];
[[appDelegate tabBarController].view removeFromSuperview];
[[appDelegate navController].view addSubview:player.view];
player.fullscreen = YES;
[player play];
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(@"willExitFullscreen...");
[[appDelegate window] addSubview:[appDelegate navController].view];
[[appDelegate window] addSubview:[appDelegate loginViewController].view];
[[appDelegate window] addSubview:[appDelegate tabBarController].view];
[player.view removeFromSuperview];
}