【问题标题】:How to determine device orientation in Custom Keyboard如何在自定义键盘中确定设备方向
【发布时间】:2014-12-26 13:03:27
【问题描述】:

我正在为 iOS8 构建自定义键盘。 我希望我的键盘支持纵向和横向模式。 如何确定设备方向? 获取设备方向目前在自定义键盘中效果不佳。

【问题讨论】:

  • 到底是什么问题?你面临什么问题?
  • 当我的键盘处于横向模式时我将如何确定键盘扩展处于横向模式。
  • 我编辑了您的问题并回答了它。希望我有所帮助

标签: ios8 custom-keyboard ios8-extension


【解决方案1】:

willRotateToInterfaceOrientationdidRotateFromInterfaceOrientation 可以使用,尽管它们在 iOS 8 中已被弃用。它们的替代品 willTransitionToTraitCollection 虽然可能不会在旋转时调用,因为键盘的特征集合不会改变。

【讨论】:

    【解决方案2】:

    很遗憾,确定设备方向的标准方法在 iOS8 自定义键盘中还不起作用。

    您可以通过检查设备的宽度和高度之间的比率来确定设备方向。 高度 > 宽度 = 纵向 宽度 > 高度 = 横向

    【讨论】:

      【解决方案3】:

      您可以使用这种方法:

      typedef NS_ENUM(NSInteger, InterfaceOrientationType)
      {
          InterfaceOrientationTypePortrait,
          InterfaceOrientationTypeLandscape
      };
      
      - (InterfaceOrientationType)orientation
      {
          InterfaceOrientationType result;
      
          if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height)
          {
              result = InterfaceOrientationTypePortrait;
          }
          else
          {
              result = InterfaceOrientationTypeLandscape;
          }
      
          return result;
      }
      

      【讨论】:

      • 如何获得自定义键盘的当前模式??
      猜你喜欢
      • 1970-01-01
      • 2015-11-10
      • 2011-05-18
      • 1970-01-01
      • 2014-09-03
      • 2018-01-18
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      相关资源
      最近更新 更多