在故事板中支持UIViewController的纵向方向模式

时间:2013-03-27 16:22:39

标签: ios objective-c xcode ios6 xcode4.6

我使用storyboard创建了UIViewController并将其链接到UIViewController类。

我想让我的UIViewController只支持Portrait Orientation,我尝试了打击代码,但似乎它不起作用。我的UIViewController仍在旋转。

我是否需要更改故事板中的任何属性?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}

2 个答案:

答案 0 :(得分:3)

在iOS6中不推荐使用

shouldAutorotateToInterfaceOrientation,您应该使用shouldAutoRotate& supportedInterfaceOrientations

在viewController中尝试这样。

- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

答案 1 :(得分:0)

我在这里找到答案: iOS 6 shouldAutorotate: is NOT being called

我的UIViewControoller由UINavigationController管理,它在iOS 6中控制它的方向:

现在,iOS容器(例如UINavigationController)不会咨询他们的孩子以确定他们是否应该自动旋转。默认情况下,应用程序和视图控制器支持的界面方向设置为iPad惯用语的UIInterfaceOrientationMaskAll和iPhone惯用语的UIInterfaceOrientationMaskAllButUpsideDown。

我必须使用新的 shouldAutorotate supportedInterfaceOrientations

将UINavigationController子类化

我看到其他帖子更喜欢添加类别而不是子类化。但对我来说,子类化工作正常。

相关问题