2014-04-29 39 views
1

我的整个应用程序被锁定在纵向方向,但是当播放视频时,我想允许所有方向仅用于视频播放。iOS 7在视频播放中解锁设备方向

故事板: TabBarController - > NavigationController - > MyVideosController - > MyVideoPlayerController

这是我试过很多之一: Allow One View to Support Multiple Orientations While Others Do Not iPhone

的问题是,我从来没有达到这个方法在我MyVideoPlayerController.m:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
+0

该方法已被弃用。 –

回答

1

根据我的经验,几乎所有在这里找到的建议都不适合你。你想要做的是(如果你正在使用故事板)添加另一个导航控制器和视图控制器。您将以模态方式推入第二个导航控制器,并将其锁定到您想要的方向。这样您的视频播放器就可以“弹出”并处于您想要的方向。

它真的很烦人。

一个替代方案(我没有真正建议)是,你可以打开AutoLayout,也许尝试IOS6版本。

+0

对不起,延迟回复Jeef。这实际上是解决方案的一部分,谢谢!之前没有工作的原因是TabBarController锁定了它的所有childcontrollers的方向。通过子类TabBarController并将方向设置为纵向,在所有方向允许的情况下,按照模式(按照您的建议)推送我的mediaPlayerView,使其工作。 – rilar

+0

我很高兴它为你工作! – Jeef

1

对于iOS-6,我已经这样做了,它大大运行

(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft; 
} 

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 
+0

请阅读上面的答案。 – rilar

1

试试这个代码,将其添加到您的类它的工作对我来说:

#pragma mark - Orientation 
- (BOOL)shouldAutorotate { 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 
+0

这个解决方案几乎为我工作。 supportedInterfaceOrientations 和shouldAutorotate被调用,但然后设备冻结。在我的“常规>部署信息”中,我为应用程序选择了“肖像”。这会导致应用程序冻结。如果我取消选中“纵向”选项,应用程序不会冻结,但shouldAutorotate方法永远不会被调用。我从哪里出发? – rilar

+0

当我设置 - (布尔)shouldAutorotate返回导致应用程序崩溃的NO。 – rilar

+0

把支持方向的代码放到你的MyVideoPlayerController中,当你回到你的viewController时,使用相同的代码,但只使用UIInterfaceOrientationMaskPortrait,并且在常规>部署信息中只检查肖像并取消选中其他选项,案件在我的应用程序,它的工作正常没有任何冻结..我认为别的东西是让你的应用程序freez – Atrash