如何捕获MPMoviePlayerController的旋转事件?

3

我已经将这段代码添加到我的ViewController中。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation != UIInterfaceOrientationPortrait) {
    [self.moviePlayerController setFullscreen:YES animated:YES]; 
} 
return YES;
}

当我旋转我的播放器后,它会在全屏模式下播放视频。 我需要在playerController(方向为Portrait)中捕获旋转事件以设置FullScreen:NO。我该怎么办?

谢谢回答。

1个回答

3

不应该在这个函数中处理moviePlayerController的方向设置。

在viewWillAppear函数中添加一个notifier。

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];}

方向变化会通知此函数。
- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

这将调用此函数,在该函数中处理moviePlayerController框架的方向

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    [self.moviePlayerController setFullscreen:NO animated:YES];    
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{
    [self.moviePlayerController setFullscreen:YES animated:YES]; 
}}

在 viewDidDisappear 中移除通知。
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];}

谢谢,兄弟。它起作用了,但旋转后我遇到了这个问题。http://img31.imageshack.us/img31/4929/20514487.png - npmrtsv
导航栏在竖屏模式下的位置正在改变。当您回到竖屏模式时,请将导航栏的顶部值设置为20.0。希望这能解决您的问题。 - Vimal Venugopalan
你可以使用 UIInterfaceOrientationIsPortrait()UIInterfaceOrientationIsLandscape() 宏来简化 -adjustViewsForOrientation: 方法。 - Rick

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接