2011-02-15 410 views
1

我有一个视图控制器,其中包括一个MPMoviePlayer里面。我隐藏了导航栏,并希望在视频暂停时显示它。MPMoviePlayerController iPhone导航栏问题

当视频加载时,它工作得很好。在我暂停后,视频导航栏出现,但它将整个播放器视图稍微向下。如何让导航栏出现而不影响播放器视图。

这里是我使用的代码:

在viewDidLoad中():

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(videoPlayerPlaybackStateChanged:) 
              name:MPMoviePlayerPlaybackStateDidChangeNotification 
              object:nil]; 

[self setWantsFullScreenLayout:YES]; 
[moviePlayer prepareToPlay]; 
//For viewing partially..... 
moviePlayer.view.backgroundColor = [UIColor blackColor]; 
//[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 410)]; 
[moviePlayer.view setFrame:[self.view bounds]]; 
moviePlayer.fullscreen = YES; 
moviePlayer.scalingMode = MPMovieScalingModeAspectFill; 

[self.view addSubview:moviePlayer.view]; 

[moviePlayer play]; 

- (void) videoPlayerPlaybackStateChanged:(NSNotification*) aNotification 
{ 
MPMoviePlayerController *player = [aNotification object]; 

if(player.playbackState == MPMoviePlaybackStatePaused){ 

    self.navigationController.navigationBar.tintColor = [UIColor blackColor]; 
    self.navigationController.navigationBarHidden = NO; 

} 
else if(player.playbackState == MPMoviePlaybackStatePlaying){ 
    self.navigationController.navigationBarHidden = YES; 
} 

[player autorelease];  
} 

预先感谢您...

回答

2

在你的病情

if(player.playbackState == MPMoviePlaybackStatePaused) 
{ 
    self.navigationController.navigationBar.tintColor = [UIColor blackColor]; 
    self.navigationController.navigationBarHidden = NO; 

}

试试吧唱歌

[self.navigationController.navigationBar setTranslucent:YES]; 
+1

谢谢你的作品就像一个魅力.. – gurkan 2011-02-15 11:51:50