版本的判断
// =
#define STDEVICE_Same(v) [[UIDevice currentDevice].systemVersion compare:v options:NSNumericSearch] == NSOrderedSame
// <
#define STDEVICE_Less(v) [[UIDevice currentDevice].systemVersion compare:v options:NSNumericSearch] == NSOrderedAscending
// >
#define STDEVICE_Than(v) [[UIDevice currentDevice].systemVersion compare:v options:NSNumericSearch] == NSOrderedDescending
// >=
#define STDEVICE_Than_Same(v) [[UIDevice currentDevice].systemVersion compare:v options:NSNumericSearch] != NSOrderedAscending
// <=
#define STDEVICE_Less_Same(v) [[UIDevice currentDevice].systemVersion compare:v options:NSNumericSearch] != NSOrderedDescending
ios 8之后屏幕的宽高发生了变化
iOS7
Currently landscape: NO
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)
Currently landscape: YES
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (20.0,0.0,300.0,568.0)
ios8
Currently landscape: NO
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)
Currently landscape: YES
UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)
UIScreen.mainScreen().applicationFrame: (0.0,0.0,568.0,320.0)
因此
在ios7中UIScreen.mainScreen().bounds是固定不变的值,在ios8中他的值是随横竖屏改变的!iOS8的statusbar还会在横屏默认隐藏
新增的api iOS8 nativebounds nativeScale
Currently landscape: YES
UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,568.0,300.0)
UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)
UIScreen.mainScreen().nativeScale: 2.0
Currently landscape: NO
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)
UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)
UIScreen.mainScreen().nativeScale: 2.0
结论iOS 8的nativebounds固定不变
写个分类
@implementation UIScreen (Additions)
+ (float)screenWidth{
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {
return [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale;
} else {
return [UIScreen mainScreen].bounds.size.height;
}
} else {
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {
return [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale;
} else {
return [UIScreen mainScreen].bounds.size.width;
}
}
}
+ (float)screenHeight{
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {
if ([UIApplication sharedApplication].statusBarFrame.size.width>20) {
return [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale-20;
}
return [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale;
} else {
if ([UIApplication sharedApplication].statusBarFrame.size.width>20) {
return [UIScreen mainScreen].bounds.size.width-20;
}
return [UIScreen mainScreen].bounds.size.width;
}
} else {
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {
if ([UIApplication sharedApplication].statusBarFrame.size.height>20) {
return [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale-20;
}
return [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale;
} else {
if ([UIApplication sharedApplication].statusBarFrame.size.height>20) {
return [UIScreen mainScreen].bounds.size.height-20;
}
return [UIScreen mainScreen].bounds.size.height;
}
}
}
+ (BOOL)isRetina{
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {
return [UIScreen mainScreen].nativeScale>=2;
} else {
return [UIScreen mainScreen].scale>=2;
}
}
+ (float)scale{
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {
return [UIScreen mainScreen].nativeScale;
} else {
return [UIScreen mainScreen].scale;
}
}