在iOS 8中,[UIScreen bounds] 、[UIScreen applicationFrame] 、Status bar、Keyboard這些frame都是根據設備真實方向來返回frame的,而在iOS 7中,不過是橫屏還是豎屏,iOS總是返回豎屏的frame,如以下輸出:
iOS 7:
-
豎屏:
-
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
-
橫屏:
-
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
iOS 8:
-
豎屏:
-
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
-
橫屏:
-
UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)
這就對某些支持橫屏的App造成了困擾,其實也只需要加兩個宏或者改造一下就行了:
-
#define SCREEN_WIDTH (getScreenSize().width)
-
#define SCREEN_HEIGHT (getScreenSize().height)
-
CGSize getScreenSize() {
-
CGSize screenSize = [UIScreen mainScreen].bounds.size;
-
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) &&
-
UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
-
return CGSizeMake(screenSize.height, screenSize.width);
-
}
-
return screenSize;
-
}