2011-06-05 69 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