gpt4 book ai didi

ios - 替代 [UIScreen mainScreen].nativeScale 是否支持 iOS 7?

转载 作者:行者123 更新时间:2023-11-28 19:00:26 26 4
gpt4 key购买 nike

有人知道以下代码的替代方案吗?我想在我的应用程序中支持 iOS 7 及更低版本,而 .nativeScale 不适用于这些固件。我无法在互联网上找到解决方案,这就是我在这里问的原因。 (通常让屏幕边界检查 568 的高度对 iPhone 6+ 不起作用)

我指的代码:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus

} else if (screenBounds.size.height == 568) {
//4 inch / iPhone 6 code

} else {
//3.5 inch code

}

提前致谢

最佳答案

所以我所做的是:首先,我有以下顺序的方法:

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 7 或更低版本的 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 设备上完全运行!

关于ios - 替代 [UIScreen mainScreen].nativeScale 是否支持 iOS 7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26436557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com