3

我已经在我的 ViewController 中添加了这段代码。

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

因此,旋转后,我的播放器以全屏模式播放视频。我需要在 playerController (OrientationPortrait) 中捕获旋转事件以设置全屏:否。我怎样才能做到这一点?感谢您的回答。

4

1 回答 1

3

moviePlayerController 的方向设置不应在此函数中处理。

在 viewWillAppear 函数中添加通知器

-(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];}
于 2012-08-22T14:02:14.590 回答