首页 文章

未检测到iPad启动方向

提问于
浏览
2

我有一个iPad应用程序正常工作,除了在发布期间的奇怪问题 . 我已经阅读了几个关于方向的问题和答案,但这仍然让我难过 .

根视图控制器是一个带有3个选项卡的UITabBarController . 其中两个选项卡具有自定义视图控制器(一个基于UIViewController,另一个基于UITableViewController),并且都受此启动方向问题的影响 . 第三个选项卡是嵌入在UINavigationController中的自定义UITableViewController .

好的,这是问题所在 . 如果我以纵向方向启动应用程序,一切都很好 . 如果我以横向方向启动它,第3个选项卡可以正常工作 . 但是,前两个选项卡以纵向方向显示,即使:

  • 状态栏方向正确显示为横向(在屏幕上展开) .

  • 标签栏视图正确显示为横向,标签居中 .

  • 对于所有方向,所有视图都返回YES for ShouldAutorotateToInterfaceOrientation .

如果我在视图控制器的viewWillAppear中调用[self interfaceOrientation]或[[UIApplication sharedApplication] statusBarOrientation],那么第三个选项卡的视图控制器报告3(横向),但前两个视图控制器报告1(纵向),即使状态栏清楚景观!

如果我将iPad旋转为纵向并返回横向,则所有3个标签的视图都会正确旋转(并且上述方法会按预期返回3) .

此外,如果我点击任何其他选项卡,然后返回选项卡#1或#2,那么它们现在将正确旋转,即使不旋转iPad本身!

我错过了什么?

6 回答

  • 3

    我发现设备方向一无所获 . 并且应该为Unknown返回YES . 这将允许它以正确的启动方向定向设备 .

    以下是我用于将此消息提升到旧消息的代码 .

    - (BOOL)shouldAutorotate{
        UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
        if (orientation == UIDeviceOrientationUnknown) return YES;
        BOOL result = [self shouldAutorotateToInterfaceOrientation:orientation];
        return result;
    }
    

    通知我返回YES如果orientation == UIDeviceOrientationUnknown . 这纠正了我的装载问题 .

  • 1

    解决方案是添加密钥

    UISupportedInterfaceOrientation

    Info.plist包含一个字符串数组,指定启动时支持的接口方向,这些是

    • UIInterfaceOrientationPortrait

    • UIInterfaceOrientationPortraitUpsideDown

    • UIInterfaceOrientationLandscapeLeft

    • UIInterfaceOrientationLandscapeRight

    However, there is the follwing issue which may lead to confusion: 至少使用来自XCode 3.2.4的SDK 3.2和iPad模拟器我发现(至少有些)Info.plist设置似乎在安装应用程序时被缓存和/或未更新 . 也就是说,添加上面的密钥并在模拟器中安装和启动应用程序没有任何效果 . 但是,从模拟器中删除应用程序修复了问题,新安装的应用程序的行为符合指定 .

  • 0

    在app delegate的applicationDidFinishLaunchingWithOptions:方法中,将视图控制器的视图添加到窗口后,添加以下内容:

    [myViewController viewDidLoad];
    

    如有必要,这将触发对shouldAutorotateToInterfaceOrientation:方法的调用 .

  • 0

    您必须将supportedDeviceOrientations添加到“myApp.plist” .

    单击此列表,添加“支持的接口方向”键并添加支持的接口方向 . 这解决了我的问题 .

    有关详细信息,请点击此链接并转至"The Application Bundle":http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html

  • 0

    我终于找到了答案:我在LoadingController中忘了这个 .

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            return YES;
    }
    
  • 1

    试试吧

    - (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
        return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
    }
    

相关问题