1.首先,在iOS8之前的[UIScreen mainScreen].bounds和 [UIScreen mainScreen].applicationFrame两者的区别在于:
1)[UIScreen mainScreen].bounds:指固定的屏幕尺寸(宽高固定)
2)[UIScreen mainScreen].applicationFrame:指除去状态栏后的固定的屏幕尺寸
比如对于 iPhone4而言,无论屏幕怎么旋转 [UIScreen mainScreen].bounds都是固定的(0,0,320,480); [UIScreen mainScreen].applicationFrame都是固定的(0,20,320,460);
2.但是在iOS8 中[UIScreen mainScreen].bounds 和 [UIScreen mainScreen].applicationFrame两者不再是固定不变的。
当旋转的时候,屏幕也会发生改变。/这是在iOS8中影响选择适配的一个原因。
iOS 7之前Window的bounds不会随着方向而变化,但是到了iOS 8以后,随着设备方向的旋转,window.bounds.size.width和window.bounds.size.height也会相应发生变化。
同样受影响的还有键盘弹起和消失的通知中[[[notificationuserInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue]的值,iOS7是以没有旋转的window坐标系为标准计算的,而iOS8是以旋转后的window坐标系为标准计算的。
还有[UIApplicationsharedApplication].statusBarFrame的尺寸也是同样的道理。
详见如下对比:(注意:UIWindow的bounds与[[UIScreen mainScreen] bounds]在各种情况都保持一致)
XCode6 +iOS8SDK+iOS8设备:
iPad横屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {1024, 768}}
[[UIScreen mainScreen] applicationFrame:{{0, 20}, {1024, 748}}
iPad竖屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {768, 1024}}
[[UIScreen mainScreen] applicationFrame:{{0, 20}, {768, 1004}}
XCode5 +iOS7SDK+iOS7设备(或者XCode6+iOS8SDK+iOS7)
iPad横屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {768, 1024}}
[[UIScreen mainScreen] applicationFrame:{{20, 0}, {748, 1024}}
iPad竖屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {768, 1024}}
[[UIScreen mainScreen] applicationFrame:{{0, 20}, {768, 1004}}
XCode6 +iOS8SDK+iOS8设备:
iPhone横屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {568, 320}}
[[UIScreen mainScreen] applicationFrame:{{0, 0}, {568, 320}}
[[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue] keyboardWillShow: {{0, 127}, {568, 193}}
iPhone竖屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {320, 568}}
[[UIScreen mainScreen] applicationFrame:{{0, 20}, {320, 548}}
[[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue] keyboardWillShow: {{0, 315}, {320, 253}}
XCode5 +iOS7SDK+iOS7设备(或者XCode6+iOS8SDK+iOS7)
iPhone横屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {320, 568}}
[[UIScreen mainScreen] applicationFrame:{{0, 0}, {300, 568}}
[[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue] keyboardWillShow: {{158, 0}, {162, 568}}
iPhone竖屏情况下
[[UIScreen mainScreen] bounds]:{{0, 0}, {320, 568}}
[[UIScreen mainScreen] applicationFrame:{{0, 20}, {320, 548}}
[[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue] keyboardWillShow: {{0, 264}, {320, 216}}
如果你的代码中有依赖UIScreen的bounds属性、UIWindow的bounds属性、键盘通知中UIKeyboardFrameEndUserInfoKey值、[UIApplication sharedApplication].statusBarFrame的地方,那么在用XCode6+iOS8SDK发布新版本前就要高度注意了~
例如:
#define IS_IPHONE_5 (IS_IPHONE && [UIScreen mainScreen].bounds.size.height == 568.f)
#define IS_IPHONE_4 (IS_IPHONE && [UIScreen mainScreen].bounds.size.height == 480.f)
就需要修改成
#define VERTICAL_SCREEN_HEIGHT MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)
#define VERTICAL_SCREEN_WIDTH MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)
#define IS_IPHONE_5 (IS_IPHONE && (VERTICAL_SCREEN_HEIGHT == 568.f))
#define IS_IPHONE_4 (IS_IPHONE && (VERTICAL_SCREEN_HEIGHT == 480.f))