我看了很多关于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/