【问题标题】:App rotation works in iOS7 but not iOS8应用轮换适用于 iOS7 但不适用于 iOS8
【发布时间】:2014-11-10 01:48:52
【问题描述】:

在 iOS8 中让我的应用在纵向和横向之间旋转时遇到问题。它在 iOS7 中运行良好。在我的主视图控制器中,我有以下内容。

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
    return YES;     // for iOS7 compatibility
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return  UIInterfaceOrientationMaskAll;
}

我可以确认(通过调试)后两个是在 iOS8 下启动时调用的,但不是在屏幕旋转时调用的。

我正在使用自动布局并且在 IB 中的错误和警告为零。 (启动时调试器中也没有)。

Info.plist 文件包含 'UISupportedInterfaceOrientations' 和 'UISupportedInterfaceOrientations~ipad' 的所有 4 个方向。

这有点不寻常,因为在模拟器 (8.1) 中,无论方向如何,应用程序总是以纵向模式启动。但是,在设备 (8.0) 上,应用程序始终以当前方向启动。然而,两者都不允许应用内轮换。

我搜索了互联网和 Apple 的文档。任何朝着正确方向的想法或指示将不胜感激。

【问题讨论】:

    标签: ios objective-c cocoa-touch ios8 uikit


    【解决方案1】:

    1) 首先点击您的项目。
    2) 然后单击常规选项卡。在部署信息下,您将找到设备方向。
    3) 检查所有四个选项。

    也许这会对你有所帮助。 如果它不起作用,请通知我。
    谢谢

    【讨论】:

    • 谢谢,但他们已经检查过了。这就是我所说的 UISupportedInterfaceOrientations 的意思。
    【解决方案2】:

    在你的 appdelegate 中使用它。

     -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else  /* iphone */
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

    【讨论】:

    • 谢谢。我错过了那个特别的电话,但没有任何区别。
    【解决方案3】:

    我终于发现了这个问题。我一直在应用程序委托的“初始化”方法中调用“beginGeneratingDeviceOrientationNotifications”:

    + (void)initialize {
        // ...
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    }
    

    这在 iOS 早期就一直运行良好,而且该调用似乎没有被弃用,但由于某种原因,它在 iOS8 中不再适用——至少在这个早期阶段没有。轻松解决。感谢所有考虑过这个问题的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多