1

我有一个UITabBar带有 5 个选项卡的基于 iOS 应用程序,其中一些选项卡是UINavigationControllers。我的一些选项卡视图支持横向,而另一些则不支持。

I have all of the auto-rotation taken care of for the views themselves, but I noticed something peculiar happening when I was testing the app - whenever a new tab is selected, the shouldAutoRotateToInterfaceOrientationmethod is not called by any UIViewController. 有没有办法在选择新标签时强制进行方向检查?

4

5 回答 5

1

创建一个方法并调用它viewWillAppear来检查方向,然后在需要时强制它。

于 2012-08-09T23:12:26.693 回答
0

方法shouldAutorotateToInterfaceOrientation:NOT supported in iOS 6。它已弃用。以防万一你是一个新手,刚开始使用 cocoa,想知道为什么你的视图控制器在 iOS 6 中搞砸了,而在 iOS 5 中却完美无缺,只需要知道 shouldAutorotateToInterfaceOrientation: 不再受支持。即使它可能会很好地Xcode 4 to 4.3工作NOT work on Xcode 4.5.

Apple 提供了一种新方法来完成这项工作,而且方式更加简洁。您改用supportedInterfaceOrientations。它返回视图控制器支持的所有界面方向,一个界面方向值的掩码。

UIInterfaceOrientationMask Enum:

这些常量是用于指定视图控制器支持的界面方向的掩码位。

    typedef enum {
     UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
     UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
     UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
     UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
     UIInterfaceOrientationMaskLandscape =
     (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
     UIInterfaceOrientationMaskAll =
     (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
     UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
     UIInterfaceOrientationMaskAllButUpsideDown =
     (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
     UIInterfaceOrientationMaskLandscapeRight),
 } UIInterfaceOrientationMask;
于 2012-08-14T12:59:40.150 回答
0

可能是您使用 ios 6.0 或更高版本,因为在 ios 6.0 及更高版本中,shouldAutoRotateToInterfaceOrientation 方法已被弃用并且不会为此调用您必须为 UINavigationController 和 UITabbarContrller 创建自己的类别,并添加一些在设备旋转时调用的方法。

于 2013-02-20T08:44:14.113 回答
0

通常当我看到这个时,这是因为标签栏中的一个视图控制器没有shouldAutoRotateToInterfaceOrientation正确设置。添加到选项卡栏的所有类都需要设置相同的值,否则会导致旋转失败。

于 2012-08-10T00:36:05.320 回答
0

iOS的 Apple UIViewController 编程指南指出:

“标签栏控制器仅在其所有托管视图控制器都支持新方向时才允许更改方向。”

如果您想支持横向,那么您需要确保所有选项卡都支持它,因为这是全有或全无的情况。

于 2012-08-14T15:11:38.747 回答