所以我所做的就是: 首先,我有以下顺序的方法:
if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus
} else if (screenBounds.size.height == 568) {
//4 inch code
} else {
//3.5 inch code
}
后来我想既然电脑停止运行if else
声明一旦他找到一个真正的我刚刚重新排列顺序如下:
if (screenBounds.size.height == 480) {
//3.5 inch code
} else if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus
} else if (screenBounds.size.height == 568) {
//4 inch code
}
这支持iOS 4或以下的iPhone 4S。在iPhone 5/5S上它仍会崩溃。这就是为什么我最终改变它到如下:
if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
//checks if device is running on iOS 8, skips if not
NSLog(@"iOS 8 device");
if (screenBounds.size.height == 480) {
//3.5 inch code
NSLog(@"iPhone 4S detected");
} else if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus
NSLog(@"iPhone 6 plus detected");
} else if (screenBounds.size.height == 568) {
//4 inch code
NSLog(@"iPhone 5/5S/6 detected");
}
} else if (screenBounds.size.height == 480) {
//checks if device is tunning iOS 7 or below if not iOS 8
NSLog(@"iOS 7- device");
NSLog(@"iPhone 4S detected");
//3.5 inch code
} else if (screenBounds.size.height == 568) {
NSLog(@"iOS 7- device");
NSLog(@"iPhone 5/5S/6 detected");
//4 inch code
}
它现在应该可以在任何iOS 7 iOS 8设备上完全工作!
你的目标是?没有iPhone 6/6 +将运行iOS 7.为什么你声称568的高度等同于iPhone 6?这是iPhone 5的高度,而不是iPhone 6(除非您的应用程序正在缩放)。 – rmaddy 2014-10-18 05:21:23
我的目标是在可能的情况下支持iOS 7和6。现在我的应用程序崩溃了(在我的iPhone 4S - 7.1.1),因为.nativeScale在iOS 8下不兼容。 我的意思正是你说的,568不适用于iPhone 6+,这就是为什么我必须实现第二种方法(.nativeScale) – LinusGeffarth 2014-10-18 05:24:05
如何:'if([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]){.. ios 8 code ..}' – 2014-10-18 05:32:19