2011-06-05 81 views
1

截图这里找到:http://i.stack.imgur.com/fru4x.pngMPMoviePlayer留下空间上方导航栏

所以我有一个UITableViewController推动具有MPMoviePlayer对象是一个UIViewController。我发现,当我作为子视图载入MPMoviePlayer时,它会创建一个状态栏。该状态栏将导航栏按下顶部,导致空白。我已经看了一堆计算器上并没有什么不同的主题似乎工作:

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

的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代码(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

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

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

手动设置大小应该摆脱白色空间。

+0

我结束了使用affinetransform只移动UINavigationBar 20像素。尽管感谢您的帮助! – Endama 2011-06-07 03:11:38