为不同的UIViewControllers设置不同的supportedInterfaceOrientations

时间:2012-09-26 11:38:16

标签: objective-c ios6 uiinterfaceorientation

因此,正如问题所示,我使用以下代码为viewcontroller设置userinterfaceOrientation。

- (BOOL) shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

我尝试将UIInterfaceOrientationMaskAll设置为另一个viewController。

之前,我检查了info-plist中Supported interface orientations的所有项目。 viewControllers都为所有方向返回true(在info-plist中设置),并且不遵守上面的代码。即使没有上述代码,IT也能工作。反正是否限制特定类的某些Supported interface orientations?我通过关注this link使其适用于iOS6之前的版本。

2 个答案:

答案 0 :(得分:1)

我能够通过将支持的定向逻辑放在自定义UINavigationController中来实现这一目标。然后我转到相关的视图控制器。

@implementation PortraitNavigationController

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

...

答案 1 :(得分:-1)

我会说在每个视图控制器上实现shouldAutorotateToInterfaceOrientation:,使其仅返回YES以支持您希望支持的方向。