ios - iOS设备实际尺寸(以英寸为单位)

标签 ios objective-c iphone ipad

我看了很多关于iOS如何获取真实大小的文章。
我找到了这样的解决方案,但我认为它不适用于所有设备。

+(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)或英寸。
或者,也许有任何图书馆可以提供帮助。

为了防止出现双重关闭:在stackoverflow中没有适当的解决方案。
例如,
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?
等等,等等...现在没有解决方案。

最佳答案

iOS中没有API可以做到这一点。使用它并确保在有新设备时更新:https://github.com/lmirosevic/GBDeviceInfo

我认为这对于AppStore来说不是问题,但也许不包括越狱包。

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

关于ios - iOS设备实际尺寸(以英寸为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37706233/

相关文章:

iphone - 如何使用 UISearchBar 启用取消按钮?

iphone - 当按下后退按钮返回到 rootViewController 时,UILabel sizeToFit 未保留

iOS 未配置 iCloud 帐户

ios - App Store Connect操作错误, "An error occurred while trying to start the iTMSTransporter"

ios - 如何使用 faSTLane 缩短 Flutter iOS 应用程序的构建时间

iOS 应用程序二进制文件被拒绝 - IPv6

ios - 在 iPhone 6 Plus 屏幕上拉伸(stretch)旧的 iOS 应用程序

ios - 如何在 iOS 应用程序中获取设备充电类型?

ios - Xcode 静态分析报告 ARC 下的一处泄漏 - CGImageRef - 如何解决

iPhone - 线程 1 EXC_BAD_INSTRUCTION 错误,控制台中未打印任何内容