【问题标题】:Determining the Orientation of the screen rather than the orientation of the device确定屏幕的方向而不是设备的方向
【发布时间】:2011-05-16 19:09:19
【问题描述】:

[[UIDevice currentDevice] orientation] 方法返回纵向和横向之外的多个方向。我很清楚检查返回的方向是否“有效”,不幸的是,当我的应用程序需要特定方向来确定要运行哪些方法时,如果返回的方向不是“有效”,我无法知道哪种方法是合适。

我已经尝试了很多解决方案,但现在我唯一能解决的问题是检查方向是LandscapeLeft 还是LandscapeRight,如果不是,我假设屏幕是纵向的。不幸的是,当设备正面朝上且屏幕为横向时,情况并非如此。

我尝试使用父视图控制器的方向:

parentController.interfaceOrientation;

不幸的是,它返回了UIDeviceOrientationUnknown。我在 SO 和 Google 上搜索遇到此问题的其他人。对我来说,苹果公司除了LandscapeLeft/RightPortraitUp/Down 之外的任何方向似乎都很愚蠢。

我真正需要的是 APPS 方向而不是设备,因为它们有时是不一致的。有什么建议吗?

【问题讨论】:

    标签: ios screen-orientation uiinterfaceorientation


    【解决方案1】:

    您是否尝试过使用UIInterfaceOrientationPortrait/UIInterfaceOrientationLandscape?使用这些方法我通常会得到很好的结果:

    if(UIInterfaceOrientationIsPortrait(viewController.interfaceOrientation)) {
        //do portrait work
    } else if(UIInterfaceOrientationIsLandscape(viewController.interfaceOrientation)){
        //do landscape work
    }
    

    你也可以试试UIDeviceOrientationIsValidInterfaceOrientation

    这些只会返回应用的方向,可能与设备的方向不同。

    如果这些都不行,你也可以试试:

    [[UIApplication sharedApplication] statusBarOrientation]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      相关资源
      最近更新 更多