2015-04-01 104 views
0

在我的项目中,我设置了方向锁定,以便它只能在肖像模式下运行。我希望mpMoviePlayer将其旋转到横向模式,一旦旋转到横向,然后保持横向模式,直到用户单击“完成”按钮。如何将mpMoviePlayerController方向设置为锁定到横向模式?

现在玩家将旋转到全屏风景,当我们旋转回肖像模式时,玩家将全屏旋转回肖像模式,并且任何进一步的旋转都不会对玩家产生影响。它将保持全画面肖像模式。

任何想法??

这是我的要求..:我希望mpMoviePlayer将其旋转到风景模式,一旦旋转到风景,然后保持横向模式,直到用户单击“完成”按钮。

任何建议?在此先感谢..

回答

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方法后锁定方向。尝试是这样的:当玩家进入景观mode.After,如果装置旋转为纵向,玩家将被旋转为纵向fullscreen.then如果我们将它旋转到

orientationBoolean

+0

forceOrientationLandscape methodn被调用一次再次景观,forceOreintation方法不被调用。另外,当我们单击完成按钮时,第一次调用forceOrientationPortrait方法。 – abhi1992 2015-04-01 12:02:04

+0

你应该自己编码;)。请查看编辑后的答案,并在为用户强制执行锁定设备方向后添加说明。如果我的回答很有用,请将其标记为这样。 – Michael 2015-04-01 12:55:35

+0

谢谢你的努力迈克尔.. :)。我认为它会工作。 – abhi1992 2015-04-03 08:02:33

0

我想你必须开启方向的应用。并在所有viewControllers中使用supportedInterfaceOrientations方法将方向锁定为纵向。基于例如创建你自己的mpPlayerVC。 MPMoviePlayerViewController并覆盖与景观相同的方法。

相关问题