【问题标题】:supporting Portrait Orientation mode for UIViewController in storyboard支持 Storyboard 中 UIViewController 的纵向模式
【发布时间】:2013-03-27 16:22:38
【问题描述】:

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

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

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

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

【问题讨论】:

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


    【解决方案1】:

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

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

    - (BOOL)shouldAutorotate {
        return NO;
    }
    
    - (BOOL)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    【讨论】:

    • 我试过了,但它仍在旋转...我需要在情节提要中做任何事情吗?
    • 在您的项目设置中,您可以将支持的方向设置为仅纵向。
    • 是的,但我还有其他需要支持横向模式的 UIViewController。
    【解决方案2】:

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

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

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

    我必须使用新的 shouldAutorotatesupportedInterfaceOrientations 来继承 UINavigationController

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

    【讨论】:

    • 如果您已经解决了问题,那就太好了。你没有提到navigationcontroller,我已经多次回答过关于子类的这类问题
    • 对不起.. 我不知道当我问 UIViewControlor 由 navigationcontroller 管理时会有所不同的问题。
    猜你喜欢
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    相关资源
    最近更新 更多