【问题标题】:How to implement iOS 8 nativeBounds code for device orientation如何为设备方向实现 iOS 8 nativeBounds 代码
【发布时间】:2015-03-17 18:16:11
【问题描述】:

在 iOS 8 中,UIScreen 类的所有权边界现在反映了设备的方向。为了解决这个问题,我可以使用属性的新 nativeBounds,而不是边界。 nativeBounds 以像素为单位。那么我为......区域中的像素放置了什么代码? (此代码在我的 AppDelegate.m 中)

     [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ];

  if (................... == 1334) { 

        UIStoryboard *iPhone6 = [UIStoryboard storyboardWithName:@"iPhone6" bundle:nil];

        UIViewController *initialViewController =[iPhone6 instantiateInitialViewController];

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];

        self.window.rootViewController = initialViewController;

        [self.window makeKeyAndVisible];
   }

或者我是否为 nativeBounds 实现了错误的整个代码?

screenBounds 不起作用...

    CGRect screenBounds=[[UIScreen mainScreen] bounds];

    if (screenBounds.size.height == 667) {  //code }

【问题讨论】:

  • 您能否提供更多细节——您的目标到底是什么?您想根据当前屏幕尺寸选择NIB文件吗?为什么要与 667 等静态尺寸值进行比较?
  • 我的应用仅使用纵向和倒置方向。使用上面的代码颠倒方向将不起作用。换句话说,当模拟器或设备倒置时,它不会像应有的那样变成纵向。上面的代码是阻止倒置方向工作的原因。那是我的问题。

标签: ios8 xcode6 appdelegate device-orientation uiscreen


【解决方案1】:

你可以使用screenBounds:

let screenBounds: CGRect = UIScreen.mainScreen().bounds

//additionally you can use these two lines to make upcoming code shorter
let screenWidth = screenSize.width
let screenHeight = screenSize.height

if (screenHeight == 1334) {
    //code goes here
}

【讨论】:

  • screenBounds 也不起作用。我在上面的原始代码中编辑了 screenBounds 的代码。没用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-10
  • 2020-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多