检测视网膜显示 [英] Detect Retina Display
问题描述
iOS SDK是否提供了一种简单的方法来检查currentDevice是否具有高分辨率显示器(视网膜)?
Does iOS SDK provides an easy way to check if the currentDevice has an high-resolution display (retina) ?
我发现这样做的最好方法现在是:
The best way I've found to do it now is :
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
// RETINA DISPLAY
}
推荐答案
为了在所有iOS设备上可靠地检测Retina显示,您需要检查设备是否运行iOS4 +以及 [UIScreen mainScreen]。 scale
property等于2.0。如果 scale
属性存在,则不能假设设备正在运行iOS4 +,因为iPad 3.2也包含此属性。
In order to detect the Retina display reliably on all iOS devices, you need to check if the device is running iOS4+ and if the [UIScreen mainScreen].scale
property is equal to 2.0. You CANNOT assume a device is running iOS4+ if the scale
property exists, as the iPad 3.2 also contains this property.
在运行iOS3.2的iPad上,刻度将在1x模式下返回1.0,在2x模式下返回2.0 - 即使我们知道该设备不包含Retina显示器。 Apple在iOS4.2中为iPad改变了这种行为:它在1x和2x模式下都返回1.0。你可以在模拟器中自己测试一下。
On an iPad running iOS3.2, scale will return 1.0 in 1x mode, and 2.0 in 2x mode -- even though we know that device does not contain a Retina display. Apple changed this behavior in iOS4.2 for the iPad: it returns 1.0 in both 1x and 2x modes. You can test this yourself in the simulator.
我测试主要的 -displayLinkWithTarget:selector:
方法屏幕存在于iOS4.x而不是iOS3.2,然后检查屏幕的比例:
I test for the -displayLinkWithTarget:selector:
method on the main screen which exists in iOS4.x but not iOS3.2, and then check the screen's scale:
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
// Retina display
} else {
// non-Retina display
}
这篇关于检测视网膜显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!