iOS设备实际尺寸以英寸为单位 [英] iOS device real size in inches

查看:200
本文介绍了iOS设备实际尺寸以英寸为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多关于iOS如何检索实际大小的帖子。
我找到了这样的解决方案,但我认为它对所有设备都无法正常工作。

I've looked a lot of post about iOS how to retrieve the real size. I found such solution but I think it doesn't work correctly for all devices.

+(float) getRealSize {
    float scale = 1;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        scale = [[UIScreen mainScreen] scale];
    }
    float dpi;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        dpi = 132 * scale;
    } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        dpi = 163 * scale;
    } else {
        dpi = 160 * scale;
    }
    CGRect originalFrame = [[UIScreen mainScreen] bounds];
    float w = originalFrame.size.width;
    float h = originalFrame.size.height;
    return dpi * sqrtf(w*w + h*h);
}

如何更新此类方法以支持所有设备?
我想要DPI(PPI)或英寸。
或者,或许,是否有任何图书馆可以提供帮助。

How to update such method to support all devices? I want DPI (PPI) or inches. Or, may be, is there any library to help.

为了防止以dublicated结束:stackoverflow中没有适当的解决方案。
例如,
iOS以编程方式获取物理屏幕尺寸?
获取以英寸为单位的物理屏幕尺寸for iPhone
如何获取iOS中的屏幕宽度和高度?
等等等...现在没有解决方案。

To prevent closing as dublicated: there is no proper solutions in stackoverflow. For, instance, iOS get physical screen size programmatically? Getting the physical screen size in inches for iPhone How to get the screen width and height in iOS? etc.,etc.,etc... no solution now.

推荐答案

iOS中没有API来获取此功能。使用此选项并确保在有新设备时进行更新: https://github.com/lmirosevic/GBDeviceInfo

There is no API in iOS to get this. Use this and make sure to update when there are new devices: https://github.com/lmirosevic/GBDeviceInfo

我不认为这对AppStore来说不是问题,但可能不包括越狱吊舱。

I don't think this would be a problem for the AppStore, but maybe don't include the jailbreak pod.

此外,您可以复制以下信息: https://github.com/lmirosevic/GBDeviceInfo/blob/master/GBDeviceInfo/GBDeviceInfo_iOS.m - 这只是关于设备的信息列表 - 没有什么疯狂的

Also, you could just copy the info out of: https://github.com/lmirosevic/GBDeviceInfo/blob/master/GBDeviceInfo/GBDeviceInfo_iOS.m -- it's just a list of info about the device -- nothing crazy

这篇关于iOS设备实际尺寸以英寸为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆