【发布时间】:2012-10-22 12:15:10
【问题描述】:
我在我的应用程序中使用 MPMoviePlayerController 来播放视频。我的应用程序仅在纵向模式下工作。我希望应用程序视频只能在横向模式下播放。所以请任何人建议我如何做到这一点。现在我的视频正在纵向模式下播放。
【问题讨论】:
标签: iphone ios ipad mpmovieplayercontroller uiinterfaceorientation
我在我的应用程序中使用 MPMoviePlayerController 来播放视频。我的应用程序仅在纵向模式下工作。我希望应用程序视频只能在横向模式下播放。所以请任何人建议我如何做到这一点。现在我的视频正在纵向模式下播放。
【问题讨论】:
标签: iphone ios ipad mpmovieplayercontroller uiinterfaceorientation
为此,您需要继承 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 而不是UIInterfaceOrientationLandscapeLeft...
【讨论】: