【问题标题】:Determine UIInterfaceOrientation of UIViewController without [[UIApplication sharedApplication] statusBarOrientation]?在没有[[UIApplication sharedApplication] statusBarOrientation]的情况下确定UIViewController的UIInterfaceOrientation?
【发布时间】:2016-09-23 12:05:19
【问题描述】:

我有一些代码,我曾经使用presentingViewController.interfaceOrientation 来确定当前UIViewController 支持的界面方向。由于interfaceOrientation 已被弃用,我已经用[[UIApplication sharedApplication] statusBarOrientation] 替换了该代码并且它工作正常。但是,在 iOS9 和 iOS8 中,它不起作用(当我检查 shouldAutorotateToInterfaceOrientationsupportedInterfaceOrientationspreferredInterfaceOrientationForPresentation 中的方向时,我得到了一些非常有趣的结果)。

所以我想知道,有没有在不使用[[UIApplication sharedApplication] statusBarOrientation] 的情况下确定视图控制器的界面方向? (需要区分横向的左右,纵向的上下颠倒)。

【问题讨论】:

  • 你能得到答案吗?
  • @DeepakSharma 我不记得了。当我查看我的代码时,我正在使用 [[UIApplication sharedApplication] statusBarOrientation] 就像我上面所说的那样,所以不确定我在 iOS9 和 iOS8 中做了什么来解决这个问题。

标签: ios uiviewcontroller uiinterfaceorientation


【解决方案1】:

您可以使用

检查方向
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                            duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation) == YES) {
    // landscape
}
else {
    // portrait.
}
}

【讨论】:

  • 我试图避免使用 UIDevice 来获取方向,因为它的行为与从状态栏中获取它有点不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-11
  • 2013-03-14
相关资源
最近更新 更多