ios屏幕尺寸

@implementation ScreenSizeAdapter

const ScreenSizeAdapter * __defaultScreenSizeAdapter = nil;

@synthesize size = _size;
@synthesize width = _width;
@synthesize height = _height;

-(void) setSize:(CGSize)screenSize {
    _size = screenSize;
    _width = screenSize.width;
    _height = screenSize.height;
}

-(void) setWidth:(CGFloat)screenWidth {
    _width = screenWidth;
    _size = CGSizeMake(_width, _height);
}

-(void) setHeight:(CGFloat)screenHeight {
    _height = screenHeight;
    _size = CGSizeMake(_width, _height);
}

-(void) setWidth: (CGFloat) width setHeight:(CGFloat) height {
    _width = width;
    _height = height;
    _size = CGSizeMake(width, height);
}

+(id) defaultAdapter {
    if(__defaultScreenSizeAdapter == nil) {
        __defaultScreenSizeAdapter = [[ScreenSizeAdapter alloc] init];
    }
    return __defaultScreenSizeAdapter;
}

-(id) init {
    return [self currentScreen];
}

-(ScreenSizeAdapter *) currentScreen {
    UIScreen * mainScreen = [UIScreen mainScreen];
    double versionNumber = [[[UIDevice currentDevice] systemVersion] doubleValue];
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    CGFloat sw = mainScreen.bounds.size.width;
    CGFloat sh = mainScreen.bounds.size.height;
    if(versionNumber >= 8.0) {
        //upper than ios 8
        [self setWidth:sw
             setHeight:sh];
    } else {
        //lower than ios 8
        if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
            [self setWidth:sh
                 setHeight:sw];
        } else {
            [self setWidth:sw
                 setHeight:sh];
        }
    }
    DDLogCDebug(@"Screen : (%f,%f)",_width,_height);
    return self;
}

-(ScreenSizeAdapter *) currentScreenWithRatio {
    UIScreen * mainScreen = [UIScreen mainScreen];
    double versionNumber = [[[UIDevice currentDevice] systemVersion] doubleValue];
    //UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    CGFloat sw = mainScreen.bounds.size.width;
    CGFloat sh = mainScreen.bounds.size.height;
    if(versionNumber >= 8.0) {
        //upper than ios 8
        if(sh > sw) {
            [self setWidth:sw
                 setHeight:sh];
        } else {
            [self setWidth:sh
                 setHeight:sw];
        }
    } else {
        //lower than ios 8
        [self setWidth:sw
             setHeight:sh];
    }
    return self;
}

/*-(CGSize) tableBarSize: (UITabBarController *) tabBarController {
    double versionNumber = [[[UIDevice currentDevice] systemVersion] doubleValue];
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if(versionNumber >= 8.0) {
        //upper than ios 8
        return tabBarController.tabBar.bounds.size;
    } else {
        //lower than ios 8
        if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
            return CGSizeMake(tabBarController.tabBar.bounds.size.height, tabBarController.tabBar.bounds.size.width);
        } else {
            return tabBarController.tabBar.bounds.size;
        }
    }
}*/

-(CGSize) navigationBarSize: (UINavigationController *) currentNavigationController {
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
        return CGSizeMake(currentNavigationController.navigationBar.frame.size.width, 32);
    } else {
        return CGSizeMake(currentNavigationController.navigationBar.frame.size.width, 44);
    }
    /*if(versionNumber >= 8.0) {
        //upper than ios 8
        return navController.navigationBar.frame.size;
    } else {
        //lower than ios 8
        if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
            return CGSizeMake(navController.navigationBar.frame.size.height, navController.navigationBar.frame.size.width);
        } else {
            return navController.navigationBar.frame.size;
        }
    }*/
}

-(CGSize) currentStatusBarSize {
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
    double versionNumber = [[[UIDevice currentDevice] systemVersion] doubleValue];
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if(versionNumber >= 8.0) {
        //upper than ios 8
        return statusBarFrame.size;
    } else {
        //lower than ios 8
        if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
            return CGSizeMake(statusBarFrame.size.height, statusBarFrame.size.width);
        } else {
            return statusBarFrame.size;
        }
    }
}



你可能感兴趣的:(ios屏幕尺寸)