检测视网膜显示屏 [英] Detect Retina Display
问题描述
iOS SDK 是否提供了一种简单的方法来检查当前设备是否具有高分辨率显示器(视网膜)?
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
属性等于 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 在 iPad 的 iOS4.2 中改变了这种行为:它在 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屋!