MPMoviePlayerController应仅在横向模式下

我在我的应用程序中使用MPMoviePlayerController来播放video。 我的应用程序仅在纵向模式下工作。 我希望应用程序video只能在横向模式下播放。 所以请任何人建议我如何做到这一点。 现在我的video正在纵向模式下播放。

为此,您需要子类化MPMoviePlayerController类。

 @interface yourMovie:MPMoviePlayerController { } @end 

并且您需要在实现中实现shouldAutoRotate方法并仅返回横向模式

 @implementation yourMovie - (BOOL)shouldAutorotate { return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait; } @end 

而且您需要创建yourMovie实例而不是MPMoviePlayerController

在MPMoviePlayerController中使用此代码,

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft]; return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } 

您也可以使用UIInterfaceOrientationLandscapeRight代替UIInterfaceOrientationLandscapeRight