2012-10-05 101 views
0

我在使应用的方向正常工作时遇到了一些麻烦。简而言之,我有两个视图控制器,我将在我的应用程序中进行切换。 ViewControllerA只能以纵向或倒置显示。 ViewControllerB可以以四种方向中的任何一种显示。方向无法正常工作

这看起来应该是非常简单的。我不知道该怎么做,但我想如果我只是拨弄shouldAutorotateshouldAutorotateToInterfaceOrientation:supportedInterfaceOrientations,那么我应该得到我想要的。出于某种原因,info.plist中的接口方向是完全覆盖视图控制器中的任何代码。如果我只允许肖像在info.plist但允许在我的viewcontroller中的一切,它旋转。而唯一被调用的方法是supportedInterfaceOrientations(其中我返回UIInterfaceOrientationMaskAll)。同样,如果我允许info.plist中的每个方向,旋转设备也会旋转viewController,即使在我的代码中我禁止任何不是纵向的方向。

我真的不知道我做错了什么。有人可以请帮忙,并告诉我我的方向代码应该看起来像ViewControllerAViewControllerB的片段,以及在info.plist中应该选择什么样的方向。谢谢!

回答

0

在功能

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

您应返回true要旋转到所有的接口,让说你想人像只

return interfaceOrientation == UIInterfaceOrientationPortrait; 

如果你想要的一切,但颠倒

return !(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 

在plist本身上它设置了更多的全局值,所以如果这个选项无效,你的代码将不会运行能够。你必须授予plist能够为两个视图做到这一点。

希望这会有所帮助。

0

iOSA中不推荐使用shouldAutorotateToInterfaceOrientation方法,而是在所有当前的全屏视图控制器中实现supportedInterfaceOrientations和shouldAutorotate方法。

还要确保您的应用程序在主窗口上执行了setRootViewController。

0

试试这个在您的AppDelegate.m

// [window_ addSubview:navController_.view]。

[window_setRootViewController:navController_];