gpt4 book ai didi

ios - 以点值检测 iPhone 6/6+ 屏幕尺寸

转载 作者:IT王子 更新时间:2023-10-29 07:34:18 24 4
gpt4 key购买 nike

鉴于新发布的 iPhone 6 screen sizes :

iPhone 6: 1334h * 750w @2x (in points: 667h * 375w)
iPhone 6+: 1920 * 1080 @3x (in points: 640h * 360w)

我想知道是否有代码允许我检测用户设备的屏幕尺寸,以便我可以根据用户的设备调整和调整 UIImages 和其他 Material 的大小。

到目前为止,我一直在使用以下内容:

- (NSString *) platform{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}

- (NSString *) platformString{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPhone3,3"]) return @"Verizon iPhone 4";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (GSM)";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (GSM)";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (GSM)";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (GSM+CDMA)";
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini (WiFi)";
if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini (GSM)";
if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini (GSM+CDMA)";
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3 (WiFi)";
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad 3 (GSM)";
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad 4 (WiFi)";
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad 4 (GSM)";
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:@"iPad4,1"]) return @"iPad Air (WiFi)";
if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air (Cellular)";
if ([platform isEqualToString:@"iPad4,4"]) return @"iPad mini 2G (WiFi)";
if ([platform isEqualToString:@"iPad4,5"]) return @"iPad mini 2G (Cellular)";
if ([platform isEqualToString:@"i386"]) return @"Simulator";
if ([platform isEqualToString:@"x86_64"]) return @"Simulator";
return platform;
}

因此,我是否应该假设 iPhone7,1iPhone7,2 是 iPhone 6 而 iPhone7,3iPhone7 .4 是优点吗?如果有人有更具体的方法来告诉它会很棒,谢谢。!

最佳答案

第一个屏幕将是设备屏幕,请注意必须在之前添加新手机的启动图像,否则该应用程序将以缩放模式运行旧应用程序:这是我用来检查的代码。 注意:这仅适用于 iOS 8 及更高版本:

UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);

检测iPhone 6 Plus代码:

#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_PHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

-(BOOL)iPhone6PlusDevice{
if (!IS_PHONE) return NO;
if ([UIScreen mainScreen].scale > 2.9) return YES; // Scale is only 3 when not in scaled mode for iPhone 6 Plus
return NO;
}

-(BOOL) iPhone6PlusUnZoomed{
if ([self iPhone6PlusDevice]){
if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES; // Height is 736, but 667 when zoomed.
}
return NO;
}

注意:如果您正在检查 iPhone 6 Plus,调整用户界面则不要依赖 .nativeScale,因为模拟器和实际设备会给出不同的结果。由于下面的评论。 Scale 是一个 CGFloat,因此,代码不应该检查相等性,因为一些浮点值可能永远不相等。


添加启动屏幕后,您可以使用新的 iPhone 尺寸,否则您的应用看起来仍会缩放。

针对新款 iPhone 11、11 Pro 和 11 Pro Max 进行了更新

iPhone 11 Pro Max 尺寸,@3x 缩放,坐标空间:414 x 896 点和1242 x 2688 像素,458 ppi,设备物理尺寸为 3.06 x 6.22 英寸或 77.8 x 158.0 毫米。 6.5 英寸超视网膜 XDR 显示屏。

iPhone 11 Pro 尺寸,@3x 缩放,坐标空间:375 x 812 点和 1125 x 2436 像素,458 ppi,设备物理尺寸为 2.81 x 5.67 英寸或 71.4 x 144.0 毫米。 5.8 英寸超视网膜 XDR 显示屏。

iPhone 11 尺寸,@2x 缩放,坐标空间:414 x 896 点和 828 x 1792> 像素,326 ppi,设备物理尺寸为 2.98 x 5.94 英寸或 75.7 x 150.9 毫米。 6.1"液态视网膜高清显示屏。

iPhone X🅂 Max 的尺寸,@3x 缩放(Apple 名称:Super Retina HD 6.5 display"),坐标空间:< strong>414 x 896 点和 1242 x 2688 像素,458 ppi,设备物理尺寸为 3.05 x 6.20 英寸或 77.4 x 157.5 毫米。

let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X🅂 Max Screen bounds: (0.0, 0.0, 414.0, 896.0), Screen resolution: (0.0, 0.0, 1242.0, 2688.0), scale: 3.0

iPhone X🅁 的尺寸,@2x 缩放比例(Apple 名称:Super Retina HD 6.1"display),坐标空间:414 x 896 点和 828 x 1792 像素,326 ppi,设备物理尺寸为 2.98 x 5.94 英寸或 75.7 x 150.9 毫米。

let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X🅁 Screen bounds: (0.0, 0.0, 414.0, 896.0), Screen resolution: (0.0, 0.0, 828.0, 1792.0), scale: 2.0

适用于 iPhone X🅂iPhone X 的尺寸,具有 @3x 缩放比例(苹果名称:Super Retina HD 5.8"display),坐标空间:375 x 812 点和 1125 x 2436 像素,458 ppi,设备物理尺寸为 2.79 x 5.65 英寸或 70.9 x 143.6 毫米。

let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X🅂 and X Screen bounds: (0.0, 0.0, 375.0, 812.0), Screen resolution: (0.0, 0.0, 1125.0, 2436.0), scale: 3.0

iPhone 8、7、6 PlusiPhone 8、7、6S Plus 尺寸,@3 倍缩放(Apple 名称:Retina HD 5.5), 坐标空间:414 x 736 点和 1242 x 2208 像素,401 ppi,屏幕物理尺寸为 2.7 x 4.8 英寸或 68 x 122 毫米:

Screen bounds: {{0, 0}, {414, 736}}, Screen resolution: <UIScreen: 0x7f97fad330b0; bounds = {{0, 0}, {414, 736}}; 
mode = <UIScreenMode: 0x7f97fae1ce00; size = 1242.000000 x 2208.000000>>, scale: 3.000000, nativeScale: 3.000000

iPhone 6iPhone 6S 的大小,@2x 缩放(Apple 名称:Retina HD 4.7),坐标空间: 375 x 667 点和 750 x 1334 像素,326 ppi,屏幕物理尺寸为 2.3 x 4.1 英寸或 58 x 104 毫米:

Screen bounds: {{0, 0}, {375, 667}}, Screen resolution: <UIScreen: 0x7fa01b5182d0; bounds = {{0, 0}, {375, 667}}; 
mode = <UIScreenMode: 0x7fa01b711760; size = 750.000000 x 1334.000000>>, scale: 2.000000, nativeScale: 2.000000

iPhone 5 进行比较的是 640 x 1136,iPhone 4 640 x 960。

注意:上传 LaunchImages,否则应用程序将按比例运行并且不会显示正确的比例或屏幕尺寸。

Comparing iPhone 6 and 6 Plus

关于ios - 以点值检测 iPhone 6/6+ 屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25756087/

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