『IOS』ios8中的UIScreen

来源:互联网 发布:中日友好靠韩国 知乎 编辑:程序博客网 时间:2024/04/20 04:29

1、在ios7中UIScreen.mainScreen().bounds是固定不变的值,在ios8中他的值是随横竖屏改变的!

在ios8中增加了2个属性:

nativeBounds :  屏幕像素,不随横竖平改变的!

nativeScale   :1(non retina)/2(retina)/3(retina hd)

3、从UIScreen.mainScreen().applicationFrame输出值看出,ios8默认横屏statusbar是隐藏掉了。你可以根据plist中

View controller-based status bar appearance的值的不同来用    




Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

Yes, it's orientation-dependent in iOS8, not a bug. You could review session 214 from WWDC 2014 for more info: "View Controller Advancements in iOS 8"

Quote from the presentation:

UIScreen is now interface oriented:

  • [UIScreen bounds] now interface-oriented
  • [UIScreen applicationFrame] now interface-oriented
  • Status bar frame notifications are interface-oriented
  • Keyboard frame notifications are interface-oriented
+ (CGSize)screenSize {    CGSize screenSize = [UIScreen mainScreen].bounds.size;    if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {        return CGSizeMake(screenSize.height, screenSize.width);    }    return screenSize;}

+ (CGRect)screenBoundsFixedToPortraitOrientation {    UIScreen *screen = [UIScreen mainScreen];    if ([screen respondsToSelector:@selector(fixedCoordinateSpace)]) {                    return [screen.coordinateSpace convertRect:screen.bounds toCoordinateSpace:screen.fixedCoordinateSpace];    }     return screen.bounds;}

#ifndef NSFoundationVersionNumber_iOS_7_1# define NSFoundationVersionNumber_iOS_7_1 1047.25#endif@implementation UIScreen (Legacy)// iOS 8 way of returning bounds for all SDK's and OS-versions- (CGRect)boundsRotatedWithStatusBar{    static BOOL isNotRotatedBySystem;    static dispatch_once_t onceToken;    dispatch_once(&onceToken, ^{        BOOL OSIsBelowIOS8 = [[[UIDevice currentDevice] systemVersion] floatValue] < 8.0;        BOOL SDKIsBelowIOS8 = floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1;        isNotRotatedBySystem = OSIsBelowIOS8 || SDKIsBelowIOS8;    });    BOOL needsToRotate = isNotRotatedBySystem && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);    if(needsToRotate)    {        CGRect screenBounds = [self bounds];        CGRect bounds = screenBounds;        bounds.size.width = screenBounds.size.height;        bounds.size.height = screenBounds.size.width;        return bounds;    }    else    {        return [self bounds];    }}@end

#define SCREEN_WIDTH (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height) : [[UIScreen mainScreen] bounds].size.width)#define SCREEN_HEIGHT (IOS_VERSION_LOWER_THAN_8 ? (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width) : [[UIScreen mainScreen] bounds].size.height)#define IOS_VERSION_LOWER_THAN_8 (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1)




0 0