强制MPMoviePlayerController在横屏模式下播放

4

我刚接触iPhone开发,正在编写我的第一个应用程序。整个应用程序只需要竖屏模式,但播放电影时除外。我正在使用MPMoviePlayerController启动电影,它在竖屏模式下播放。如何强制MPMoviePlayerController在横屏模式下播放所有电影。

我正在使用Xcode 4,并为iOS 4.0及以上版本构建应用程序。我需要在info.plist中输入一些设置,以允许MPMoviePlayerController在横屏模式下播放吗?

这是我用来初始化MPMoviePlayerController的代码:

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL: url]; 
[self.view addSubview:theMovie.view];
theMovie.allowsAirPlay=YES;
[theMovie setFullscreen:YES animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play]; 
2个回答

6

将播放器嵌入其自己的视图控制器中,并按照以下方式实现shouldAutorotateToInterfaceOrientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

这对我没用 - 我有一个视图控制器来呈现电影,它完全是横向模式,但电影仍然在纵向模式下启动... 有什么想法吗? - jesses.co.tt

0
创建一个继承自MPMoviePlayerViewController的子类:

@interface MyMoviePlayerViewController ()

@end

@implementation MyMoviePlayerViewController

- (BOOL)shouldAutorotate { return NO; }
- (NSUInteger)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskLandscape;
}

@end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接