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

后端 未结 18 1004
北恋
北恋 2020-11-22 16:55

I ran the following code in both iOS 7 and iOS 8:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landsca         


        
18条回答
  •  Happy的楠姐
    2020-11-22 17:38

    This will give correct device in iOS7 and iOS8 both,

    #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    #define IS_PORTRAIT         UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)
    
    + (BOOL)isIPHONE4{
    
    // < iOS 8.0
    if(SYSTEM_VERSION_LESS_THAN(@"8.0")){
    
            if ([self getDeviceWidth] == 320.0 && [self getDeviceHeight] == 480.0) {
                return YES;
            } else {
                return NO;
            }
    
    // >= iOS 8.0
    }else{
    
        if(IS_PORTRAIT){
    
            if ([self getDeviceWidth] == 320.0 && [self getDeviceHeight] == 480.0) {
                return YES;
            } else {
                return NO;
            }
    
        }else{
    
            if ([self getDeviceWidth] == 480.0 && [self getDeviceHeight] == 320.0) {
                return YES;
            } else {
                return NO;
            }
    
        }
    
    }
    
    
    }
    
    + (BOOL)isIPHONE5{
    
    
    // < iOS 8.0
    if(SYSTEM_VERSION_LESS_THAN(@"8.0")){
    
        if ([self getDeviceWidth] == 320.0 && [self getDeviceHeight] == 568.0) {
            return YES;
        } else {
            return NO;
        }
    
        // >= iOS 8.0
    }else{
    
        if(IS_PORTRAIT){
    
            if ([self getDeviceWidth] == 320.0 && [self getDeviceHeight] == 568.0) {
                return YES;
            } else {
                return NO;
            }
    
        }else{
    
            if ([self getDeviceWidth] == 568.0 && [self getDeviceHeight] == 320.0) {
                return YES;
            } else {
                return NO;
            }
    
        }
    
    }
    
    }
    
    + (BOOL)isIPHONE6{
    
    // < iOS 8.0
    if(SYSTEM_VERSION_LESS_THAN(@"8.0")){
    
        if ([self getDeviceWidth] == 375.0 && [self getDeviceHeight] == 667.0) {
            return YES;
        } else {
            return NO;
        }
    
        // >= iOS 8.0
    }else{
    
        if(IS_PORTRAIT){
    
            if ([self getDeviceWidth] == 375.0 && [self getDeviceHeight] == 667.0) {
                return YES;
            } else {
                return NO;
            }
    
        }else{
    
            if ([self getDeviceWidth] == 667.0 && [self getDeviceHeight] == 375.0) {
                return YES;
            } else {
                return NO;
            }
    
        }
    
    }
    
    
    }
    + (BOOL)isIPHONE6Plus{
    
    
    // < iOS 8.0
    if(SYSTEM_VERSION_LESS_THAN(@"8.0")){
    
        if ([self getDeviceWidth] == 414.0 && [self getDeviceHeight] == 736.0) {
            return YES;
        } else {
            return NO;
        }
    
        // >= iOS 8.0
    }else{
    
        if(IS_PORTRAIT){
    
            if ([self getDeviceWidth] == 414.0 && [self getDeviceHeight] == 736.0) {
                return YES;
            } else {
                return NO;
            }
    
        }else{
    
            if ([self getDeviceWidth] == 736.0 && [self getDeviceHeight] == 414.0) {
                return YES;
            } else {
                return NO;
            }
    
        }
    
    }
    
    
    }
    
    + (CGFloat)getDeviceHeight{
    
    //NSLog(@"Device width: %f",[UIScreen mainScreen].bounds.size.height);
    return [UIScreen mainScreen].bounds.size.height;
    }
    + (CGFloat)getDeviceWidth{
    
    //NSLog(@"Device width: %f",[UIScreen mainScreen].bounds.size.height);
    return [UIScreen mainScreen].bounds.size.width;
    }
    

    //You may add more devices as well(i.e.iPad).

提交回复
热议问题