如何将mpMoviePlayerController方向设置为横向模式?

时间:2015-04-01 08:42:16

标签: ios objective-c iphone rotation mpmovieplayercontroller

在我的项目中,我设置了方向锁定,使其只能在纵向模式下运行。我希望mpMoviePlayer在旋转到横向后将其旋转到横向模式,然后保持横向模式,直到用户点击&#34 ;完成"按钮。

现在,播放器将全屏旋转至横向,当我们旋转回纵向模式时,播放器将全屏旋转回纵向模式,并且不会对播放器进行任何进一步旋转。它将保持纵向全屏模式

任何想法??

这是我的要求..:我希望mpMoviePlayer在旋转到横向后将其旋转到横向模式,然后保持横向模式,直到用户点击"完成"按钮。

任何建议?提前致谢..

2 个答案:

答案 0 :(得分:1)

首先将它放在播放视频的ViewController中:

- (BOOL)shouldAutorotate
{
    return YES;
}

然后实施强制所需方向或任何方向的方法:

- (void)forceOrientationPortrait
{
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}

- (void)forceOrientationLandscape
{
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}

最后,您可以在MoviePlayer全屏显示和退出时添加观察者。观察者触发前面提到的方向改变方法:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceOrientationLandscape) name:MPMoviePlayerDidEnterFullscreenNotification object:Nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceOrientationPortrait) name:MPMoviePlayerDidExitFullscreenNotification object:Nil];
}

所有放在一起的应该是这样的:

completecode

我希望通过这个你可以实现你的目标。

- 编辑 -

如果要在强制设备为纵向/横向后锁定方向,则可以实现Boolean相应地设置ShouldAutorotate方法。尝试这样的事情:

orientationBoolean

答案 1 :(得分:0)

我猜你必须为应用程序解锁方向。并在所有viewControllers中使用supportedInterfaceOrientations方法将方向锁定为纵向。根据例如MPMoviePlayerViewController创建自己的mpPlayerVC,并使用landscape覆盖相同的方法。