MPMoviePlayerController只能在横向模式下使用

时间:2012-10-22 12:15:11

标签: iphone ios ipad mpmovieplayercontroller uiinterfaceorientation

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

2 个答案:

答案 0 :(得分:3)

为此,您需要继承MPMoviePlayerController类。

@interface yourMovie:MPMoviePlayerController
{
}
@end

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

@implementation yourMovie

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

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

答案 1 :(得分:2)

在MPMoviePlayerController中使用此代码,

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

而不是UIInterfaceOrientationLandscapeLeft,您也可以使用UIInterfaceOrientationLandscapeRight ...

相关问题