我有一个基于UITabBar的iOS应用程序,有5个标签,其中一些是UINavigationController。我的一些标签视图支持风景,而另一些则不支持。
我已经处理了视图本身的所有自动旋转,但我注意到在测试应用程序时发生了一些奇怪的事情-每当选择一个新选项卡时,任何UIViewController都不会调用shouldAutoRotateToInterfaceOrientation方法。有没有办法在选择新选项卡时强制进行方向检查?
发布于 2012-08-10 07:12:27
创建一个方法并在viewWillAppear中调用它来检查方向,然后在需要时强制它。
发布于 2012-08-10 08:36:05
通常,当我看到这种情况时,是因为选项卡栏中的某个视图控制器没有正确设置shouldAutoRotateToInterfaceOrientation。添加到选项卡栏中的所有类都需要设置相同的值,否则会导致循环出错。
发布于 2012-08-14 20:59:40
方法shouldAutorotateToInterfaceOrientation:为NOT supported in iOS 6。它已被弃用。如果你是一个新手,刚刚开始使用可可,并且想知道为什么你的视图控制器在iOS 6中搞砸了,而在iOS 5中却是完美的,只要知道shouldAutorotateToInterfaceOrientation:不再被支持就行了。即使它可以与Xcode 4 to 4.3很好地协同工作,它也将NOT work on Xcode 4.5.
苹果提供了一种新的方法,以一种更干净的方式完成这件事。您可以改用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;https://stackoverflow.com/questions/11892653
复制相似问题