0

我使用情节提要创建了 UIViewController 并将其链接到 UIViewController 类。

我想让我的 UIViewController 只支持肖像方向,我尝试了打击代码,但它似乎不起作用。我的 UIViewController 仍然旋转。

我需要更改情节提要中的任何属性吗?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

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

2 回答 2

3

shouldAutorotateToInterfaceOrientation在 iOS6 中已弃用,您应该使用shouldAutoRotate& supportedInterfaceOrientations

在您的 viewController 中尝试这样的操作。

- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
于 2013-03-27T16:25:03.280 回答
0

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

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

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

我必须使用新的shouldAutorotatesupportedInterfaceOrientations子类 UINavigationController

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

于 2013-03-27T17:50:51.080 回答