MPMoviePlayer在导航栏上方留出空格

时间:2011-06-05 23:31:08

标签: iphone xcode mpmovieplayer

在此处找到屏幕截图:http://i.stack.imgur.com/fru4x.png

所以我有一个UITableViewController推送一个UIViewController,里面有一个MPMoviePlayer对象。我发现的是,当我将MPMoviePlayer作为子视图加载时,它会创建一个状态栏。此状态栏将导航栏向下推到顶部,从而产生空白区域。我在stackoverflow上看了很多不同的主题,似乎没有任何工作:

iPhone: Weird space at the top of UINavigationController

Not sure why UIView is being nudged up by around 10px

Empty (white) line under UITableView after close MPMoviewPlayer from fullscreen mode

Hide StatusBar from MPMoviePlayerController

使用以下代码(PresetViewController.m)推送UIViewController:

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

1 个答案:

答案 0 :(得分:1)

尝试将viewController.view的框架(viewController.view.frame)设置为占用整个屏幕的CGRect:

viewController.view.frame = CGRectMake( 0, 0, 320, 480);

手动设置大小应该摆脱空白区域。