【问题标题】:iOS 5.0 Modal View Not Rotating(Story Boards)iOS 5.0 模式视图不旋转(故事板)
【发布时间】:2013-01-18 08:50:22
【问题描述】:

我使用故事板。在我想旋转的每个视图控制器中,我都包含了这样的方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

在 iOS 6 中,它可以很好地旋转到我在故事板上的横向和纵向视图。

在 iOS 5 中,父视图控制器会旋转,但模态框在屏幕上时不会旋转,它们只会在屏幕上之前旋转,而不会在屏幕上旋转。因此,当用户改变方向时,它保持不变。父级在屏幕上会改变,但模态将采用父级的方向,但在屏幕上不会改变。如何让我的模态视图像 iOS 6 一样在屏幕上旋转时工作。模态视图是通过情节提要创建的。

编辑*

当我弹出一个模态框时,模态框不会旋转。我怎样才能解决这个问题?

【问题讨论】:

    标签: iphone ios objective-c ipad storyboard


    【解决方案1】:

    在 iOS5 和 iOS6 中,旋转的处理方式不同。我使用下面的代码来支持这两个版本。

    // iOS5
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    
    // iOS6
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }
    
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    

    shouldAutorotateToInterfaceOrientation: 在 iOS6 中已弃用。你可以在这里阅读:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:

    【讨论】:

    • 这很有趣,因为它在 iOS6 上运行良好,稍后我会处理这个弃用。但是我确实使用 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } 对于 iOS 5 但问题是,它不在模态视图上旋转。
    • 对不起,我没有正确阅读问题哈哈。这段代码是模态视图控制器和呈现模态视图的视图控制器吗?
    • 用户在 iOS 5 iPad 上启动应用程序。在他们旋转的第一个屏幕上,它会自动旋转。当他们单击按钮时,下一个视图会以模态方式呈现,并且它将以第一个视图所在的任何方向显示。当用户更改方向时,当模型视图向上时,屏幕将不会更改方向,直到模态视图关闭.
    • 模态背后的视图是否旋转?
    • 是的。父视图控制器会。当您返回时,它将处于新的方向
    猜你喜欢
    • 2012-03-08
    • 2012-10-17
    • 2013-10-09
    • 2012-01-30
    • 2012-08-22
    • 1970-01-01
    • 2012-04-21
    • 2012-04-21
    • 1970-01-01
    相关资源
    最近更新 更多