首页 文章

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

提问于
浏览
0

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

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

任何的想法??

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.

任何建议??提前谢谢..

2 回答

  • 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

  • 0

    我想你必须为应用程序解锁方向 . 并在所有viewControllers中使用 supportedInterfaceOrientations 方法将方向锁定为纵向 . 基于例如创建自己的mpPlayerVC MPMoviePlayerViewController 并使用横向覆盖相同的方法 .

相关问题