截图在这里:http: //i.stack.imgur.com/fru4x.png
所以我有一个 UITableViewController 推送一个 UIViewController ,其中有一个 MPMoviePlayer 对象。我发现当我将 MPMoviePlayer 作为子视图加载时,它会创建一个状态栏。此状态栏将导航栏向下推到顶部,从而产生空白。我在 stackoverflow 上查看了一堆不同的主题,但似乎没有任何效果:
iPhone:UINavigationController 顶部的奇怪空间
从全屏模式关闭 MPMoviewPlayer 后 UITableView 下的空(白)行
从 MPMoviePlayerController 隐藏状态栏
UIViewController 使用以下代码 (PresetViewController.m) 推送:
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
//PresetNode *tempNode = [appDelegate.presetData objectAtIndex:row];
..... SOME DATA IS LOADED HERE
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
MoviePlayer *player = [[MoviePlayer alloc] initWithNibName:nil bundle:nil andVideoArray: presetVideoURLs];
[self.navigationController pushViewController:player animated:NO];
[player playVideoAtIndex:0];
[player release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
当视图控制器加载时,由于某种原因,即使我在 MoviePlayer.m 中使用此代码,它也会加载到其视图顶部的状态栏中:
- (void)viewDidAppear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
我将电影设置为横向模式并播放。然后我检查是否按下了完成按钮。如果按下完成按钮,我会弹出视图。出于某种原因,当视图被弹出时,它后面的 uitableviewcontroller 会被向下推几个像素。电影播放器创建的状态栏将所有内容向下推。这是电影播放器代码(MoviePlayer.m):
-(void) playVideoAtIndex: (NSInteger)index{
NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent: [self.movieArray objectAtIndex:index]];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
self.yourMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];
[yourMoviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[[self navigationController] setNavigationBarHidden: YES];
yourMoviePlayer.scalingMode = MPMovieScalingModeFill;
[[yourMoviePlayer view] setTransform:CGAffineTransformMakeRotation(M_PI/2)];
self.yourMoviePlayer.view.frame = self.view.frame;
[yourMoviePlayer setFullscreen:YES animated:NO];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(checkForNextMovie:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:yourMoviePlayer];
[[self view]addSubview:yourMoviePlayer.view];
//[[self navigationController] presentMoviePlayerViewControllerAnimated:self];
//---play movie---
[yourMoviePlayer play];
}
-(void) checkForNextMovie:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
NSNumber *reason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
[yourMoviePlayer release];
if((currentIndex+1) == [self.movieArray count] || [reason intValue] == MPMovieFinishReasonUserExited){
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
[player.view removeFromSuperview];
[[self navigationController] setNavigationBarHidden: NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
//self.wantsFullScreenLayout = YES;
[[self navigationController] popViewControllerAnimated:NO];
if ([UIApplication sharedApplication].statusBarOrientation != self.interfaceOrientation) {
[[UIApplication sharedApplication] setStatusBarOrientation:self.interfaceOrientation animated:NO];
}
}
else{
currentIndex++;
[self playVideoAtIndex: currentIndex];
}
}