MPMoviePlayerController iPhone导航栏问题

时间:2011-02-15 08:02:46

标签: iphone mpmovieplayercontroller

我有一个视图控制器,里面包含一个MPMoviePlayer。我隐藏了导航栏,希望在视频暂停时显示它。

加载视频后,效果很好。暂停后,视频导航栏出现,但它将整个播放器视图推向一点点。如何在不影响播放器视图的情况下显示导航栏。

这是我使用的代码:

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

提前谢谢你......

1 个答案:

答案 0 :(得分:2)

在您的情况下

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

}

尝试使用

    [self.navigationController.navigationBar setTranslucent:YES];