【问题标题】:Incorrect rotation of a view controller in iOS 6iOS 6 中视图控制器的不正确旋转
【发布时间】:2012-11-04 17:34:48
【问题描述】:

在我的应用程序中,我一直在使用现已弃用的 shouldAutoRotateToFace 方法。现在,当使用 iOS 6 模拟器时,我的所有子视图都旋转到纵向,而设备处于横向。有谁知道可能导致这种情况的原因?我已经尝试用 supportOrientations 方法(或者你现在应该使用的任何方法)替换我的主视图控制器中的 should autorotate。

【问题讨论】:

    标签: iphone objective-c ios xcode rotation


    【解决方案1】:

    如果您可以登录 Apple 开发者论坛,check out this thread。

    基本上,这是对我有帮助的信息:


    1.我必须设置window.rootViewController = mainViewController

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

    2.对于视图控制器

    - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
    

    没有只是返回YES,我必须添加

    - (NSUInteger)supportedInterfaceOrientations
    

    返回相同的值

    3. 已添加

    - (BOOL)shouldAutorotate {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
                UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
    }
    

    到 mainViewController.m

    4.已添加

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
                UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
    }
    

    到 appDelegate.m(我相信这是可选的,用于设置默认值,以防它们未在应用的 Info.plist 文件或单个视图控制器中指定)



    因为我希望我的代码向后兼容回 3.0,所以我没有使用 All 方向掩码,因为我需要使用 XCode 4.3

    进行编译

    【讨论】:

    • 这看起来正是我所需要的 - 我尝试了所有这些但分开,因为我认为它们是单独的解决方案。
    • "我必须在应用程序的委托中设置 window.rootViewController = mainViewController" 对我来说是这样做的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多