【问题标题】:iOS Detect Today Extension OrientationiOS 检测今日扩展方向
【发布时间】:2015-04-14 23:20:06
【问题描述】:

我正在尝试检测 Today Extension 的方向,但似乎没有一种典型方法有效。

我尝试了以下方法:

[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft;

[UIDevice currentDevice]orientation] = UIDeviceOrientationLandscapeLeft;

我什至尝试过使用 CMMotionManger。

感谢您的帮助。

【问题讨论】:

    标签: ios iphone ios8-today-widget today-extension


    【解决方案1】:

    似乎没有针对扩展的防弹解决方案。

    查看此答案以了解可能的解决方法 - https://stackoverflow.com/a/26023538/2797141

    【讨论】:

      【解决方案2】:

      任何正常方式都无法检测到方向。但是,每次小部件打开时,它都会调用“viewDidLoad”。因此,在 viewDidLoad 中,据此检测屏幕宽度和高度并确定您自己的方向。

      int startOrientation;
      int screenWidth = self.view.frame.size.width; //Screen Width
      int screenHeight = self.view.frame.size.height; // Screen Height;
      
      if (screenWidth > screenHeight) {
          startOrientation = @"landscape";
      } else {
          startOrientation = @"portrait";
      }
      

      【讨论】:

      • 这不起作用。考虑容器视图的情况......在这种情况下,当您的屏幕处于纵向时,宽度很容易大于高度。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      相关资源
      最近更新 更多