【问题标题】:How to update my UIViewController to current orientation when use pushViewController?使用 pushViewController 时如何将我的 UIViewController 更新为当前方向?
【发布时间】:2010-06-14 03:12:46
【问题描述】:

我用过这段代码,但它是私有 API,苹果也拒绝!

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

如果我在横向旋转我的设备然后打开我的应用程序,它将显示为纵向模式,我需要将我的设备旋转到另一个方向然后它会更新。

如何在调用 UIViewController 时将其更新为正确的方向?

【问题讨论】:

    标签: iphone uiviewcontroller


    【解决方案1】:

    您应该在 UIViewController 类中使用以下代码:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    

    如果你需要在运行时更新方向,那么你必须返回其他常量

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

    【讨论】:

    • 感谢Yakov,当设备改变方向时,此代码将调用,它可以回答我的问题,即当推送我的视图时它会显示不正确的方向。所以如果我用 setOrientation 强制它:它将被苹果拒绝。
    • 所以...您还可以尝试将“初始界面方向”属性添加到 info.plist 中。例如:您可以设置值“横向(右主页按钮)”或“纵向(顶部主页按钮)”。
    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多