【问题标题】:iPad UIInterfaceOrientation after launch image启动图像后的 iPad UIInterfaceOrientation
【发布时间】:2023-10-18 21:20:01
【问题描述】:

我的应用程序应该只支持横向模式,所以我配置 info.plist 键以正确的方式获取它。
我的根视图控制器是一个自定义 UINavigationController,我添加到主窗口并实现了

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

问题在于,在 applicationDidFinishLaunching 之后,interfaceOrientation 始终是 UIInterfaceOrientationLandscapeRight,即使应用程序以 UIInterfaceOrientationLandscapeLeft 方向启动。
结果是启动图像的方向正确,而应用程序是颠倒的。
摇晃设备片刻,使控制器再次按正确方向旋转。

这是一个错误吗?我该如何解决?

【问题讨论】:

    标签: ipad rotation launch uiinterfaceorientation launching-application


    【解决方案1】:

    这对我很有用

    • (BOOL)应该自动旋转到接口方向(UIInterfaceOrientation)接口方向 {

      if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {

      返回是;

      }其他{

      返回否;

      }

      }

    祝你好运

    【讨论】:

    • 这和我的代码一样。问题不在于 if 语句,而是 interfaceOrientation 应该是 interfaceOrientationLandscapeLeft,而不是 interfaceOrientationLandscapeRight。