MPMoviePlayerController不会在iOS 5中以全屏模式更改方向

在我的应用程序,我只支持肖像模式,并使用UINavigationController作为RootViewController 。 但是,当我玩电影使用MPMoviePlayerController和播放器是全屏比我希望它支持两种landscape模式也。

这是使用这个伟大的代码@ChrisBallinger 这在iOS6,但它不在iOS5工作经过在谷歌长时间search,我无法find这样贴在这里的解决scheme。 请帮助解决这个问题。

我也尝试过inheritancenavigationcontroller并设置它在这里find的旋转代码,但没有运气。

我的沙盒应用程序: https : //github.com/comonitos/programatical_device_orientation

解决scheme很简单:

在接口(h文件)中:

  BOOL rotated; 

在执行(m文件)中:1.重写

  -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return rotated; } 

2调用[自设置]

  -(void) setup { rotated = YES; [[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft]; rotated = NO; } 

你将不得不做的是…

首先在下面的viewdidload方法中实现通知…

  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

现在执行下面的旋转方法

  #pragma mark - Rotate Screen Method - (void)rotate:(NSNotification *)n { // if (!isFullScreen) // return; switch ([[UIDevice currentDevice] orientation]) { case UIDeviceOrientationLandscapeLeft: playerView.transform = CGAffineTransformMakeRotation(M_PI / 2);//playerview is view in which you have added MPMoviePlayerViewController object playerView.frame = CGRectMake(0, 0, 768, 1024); break; case UIDeviceOrientationLandscapeRight: playerView.transform = CGAffineTransformMakeRotation(-M_PI / 2); playerView.frame = CGRectMake(0, 0,768, 1024); break; case UIDeviceOrientationPortrait: playerView.transform = CGAffineTransformIdentity; playerView.frame = CGRectMake(0, 0, 768, 1024); break; case UIDeviceOrientationPortraitUpsideDown: playerView.transform = CGAffineTransformMakeRotation(M_PI); playerView.frame = CGRectMake(0, 0, 768, 1024); break; default: break; } } 

让我知道它工作与否!

快乐编码!