【问题标题】:iPhone - getting device orientation in first view controller's view will appeariPhone - 在第一个视图控制器的视图中获取设备方向将出现
【发布时间】:2011-11-30 20:24:21
【问题描述】:

我的应用中只有一个应用委托和视图控制器。 该应用程序适用于纵向和横向模式。 在我的视图控制器的 viewWillAppear 方法中,我使用以下代码获取设备的方向:

UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])

当我第一次运行应用程序时,即使我的设备是纵向的,它也会将结果显示为横向。 为什么会这样。我该如何解决这个问题?

【问题讨论】:

    标签: iphone uidevice


    【解决方案1】:

    我对 currentDevice.orientation 有很多问题试试这个:

    UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])
    

    【讨论】:

      【解决方案2】:
      UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
      
      
      if (UIDeviceOrientationIsLandscape(deviceOrientation)
      {
         //LandscapeView
      }
      else
      {
         //PortraitView
      }
      

      【讨论】:

        【解决方案3】:

        来自UIDevice 的文档:

        此属性的值始终返回 0,除非方向 通知已通过调用启用 beginGeneratingDeviceOrientationNotifications。

        如果您查看“orientation”返回的实际值,您会发现它是“UIDeviceOrientationUnknown”。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-22
          • 1970-01-01
          • 2010-11-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多