简体   繁体   English

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

[英]How to set the mpMoviePlayerController orientation locked to landscape mode?

In my project,i have set orientation lock so that it should run only in portrait mode.I want the mpMoviePlayer to rotate it to landscape mode once rotated to landscape and then remain in the landscape mode until the user click "done " button. 在我的项目中,我设置了方向锁定,因此它只能在纵向模式下运行。我希望mpMoviePlayer在旋转到横向后将其旋转到横向模式,然后保持横向模式,直到用户单击“完成”按钮。

Now the player will rotate to landscape in fullscreen and when we rotate back to portrait mode,the player will rotate back to portrait mode in full screen and any further rotations are not effected to the player.It will remain in portrait fullscreen mode. 现在,播放器将以全屏模式旋转为横向模式,当我们旋转回纵向模式时,播放器将以全屏模式旋转回到纵向模式,并且不会对播放器产生任何进一步的旋转。它将保持在纵向全屏模式下。

Any idea?? 任何想法??

this is my requirement..:I want the mpMoviePlayer to rotate it to landscape mode once rotated to landscape and then remain in the landscape mode until the user click "done " button. 这是我的要求。.:我希望mpMoviePlayer在旋转到横向后将其旋转到横向模式,然后保持横向模式,直到用户单击“完成”按钮。

any suggestion??Thanks in advance.. 有什么建议吗?谢谢。

First of all put this in your ViewController that plays the video: 首先,将其放入播放视频的ViewController中:

- (BOOL)shouldAutorotate
{
    return YES;
}

Then implement methods that force the desired orientation or whatever orientations you want: 然后实施强制所需方向或所需方向的方法:

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

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

Last you add observers for when the MoviePlayer goes fullscreen and when it exits. 最后,您为MoviePlayer何时全屏显示和何时退出添加观察者。 The observers trigger the before mentioned orientation change methods: 观察者触发前面提到的方向更改方法:

- (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];
}

All put together it should look like this: 全部放在一起看起来应该像这样:

completecode

I hope with this you can accomplish your goals. 我希望您可以实现自己的目标。

-- edit -- -编辑-

If you want to lock the orientation after forcing the device to portrait/landscape then you could implement a Boolean that sets the ShouldAutorotate method accordingly. 如果要在将设备强制设置为纵向/横向后锁定方向,则可以实现一个Boolean ,该Boolean会相应地设置ShouldAutorotate方法。 Try something like this: 尝试这样的事情:

orientationBoolean

I guess you have to unlock orientations for the app. 我猜您必须解锁应用程序的方向。 And use supportedInterfaceOrientations method in all viewControllers to lock the orientation to portrait. 并在所有viewController中使用supportedInterfaceOrientations方法将方向锁定为纵向。 create your own mpPlayerVC based on eg MPMoviePlayerViewController and override the same method with landscape. 基于MPMoviePlayerViewController创建自己的mpPlayerVC并使用landscape覆盖相同的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM