我正在 Xcode 6 中构建一个横向应用程序。当我在iOS 8.3模拟器上运行它时,[UIScreen mainScreen].bounds
是667x375
,但是当我在iPhone 6 iOS 8上运行它时,[UIScreen mainScreen].bounds
是375x667
。这给我的应用程序带来了问题,因为许多元素的大小都与屏幕边界有关。我知道[UIScreen mainScreen].bounds
iOS 8中发生了变化,但这不是问题所在。它应该在设备和模拟器上667x375
。我会提供代码,但我不知道问题出在哪里。
iOS 8.3 iPhone6 Simulator
Portlait
bounds:{{0, 0}, {375, 667}}
applicationFrame:{{0, 20}, {375, 647}}
nativeBounds:{{0, 0}, {750, 1334}}
Landscape
bounds:{{0, 0}, {667, 375}}
applicationFrame:{{0, 0}, {667, 375}}
nativeBounds:{{0, 0}, {750, 1334}}
iOS 8.3 iPhone6 Device
Portlait
bounds:{{0, 0}, {375, 667}}
applicationFrame:{{0, 20}, {375, 647}}
nativeBounds:{{0, 0}, {750, 1334}}
Landscape
bounds:{{0, 0}, {667, 375}}
applicationFrame:{{0, 0}, {667, 375}}
nativeBounds:{{0, 0}, {750, 1334}}
在iOS 8.3上,模拟器和设备的结果完全相同。如果报告的情况仅发生在iOS 8设备上,如何将应用程序定位到iOS 8.3?
在 iOS8 上,窗口的框架将随着设备方向而变化。我认为 667x375 是您的设备横向时的大小。
这是我用来将屏幕尺寸更改回iOS 8之前的快速类方法(切换高度和宽度)
+ (CGSize)getScreenSize {
CGSize screenSizeRef = [[UIScreen mainScreen] bounds].size;
if (screenSizeRef.width > 450 && UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
// iPhone 6+ width on portrait is 414
return CGSizeMake(screenSizeRef.height, screenSizeRef.width);
}
if (screenSizeRef.width > 900 && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return CGSizeMake(screenSizeRef.height, screenSizeRef.width);
}
return screenSizeRef;
}
因此,不要调用 [[UIScreen mainScreen] bounds]
,而是将此方法放在一个新类中(以便您可以从程序中的任何位置访问它),并将屏幕大小引用设置为返回值 getScreenSize