简体   繁体   中英

Universal iphone, ipad app

I'm using scale < 1.1 or > 1.9 to differentiate between low res and retina versions:

if (([[UIScreen mainScreen] scale] < 1.1) {}
if (([[UIScreen mainScreen] scale] > 1.9) {}

My question: Are all iPhones that have a scale < 1.1 in low-res and all iPads that have a scale of < 1.1 in low-res?

All iPhones that have a scale > 1.9 retina and all iPads that have a scale > 1.9 retina?

It seems to be the case, but there are so many devices out there I just want to be sure.

As long as you can count on iOS 4.0 or higher, what you suggested will work fine. As others have noted, however, you don't need to check for fractional scales. From the UIScreen documentation :

The default logical coordinate space is measured using points, where one point is approximately equal to 1/160th of an inch. If a device's screen has a reasonably similar pixel density, the scale factor is typically set to 1.0 so that one point maps to one pixel. However, a screen with a significantly different pixel density may set this property to a higher value.

For all current devices scale will return either 1.0 or 2.0.

One caveat to be aware of is discussed in this StackOverflow answer on how to Detect Retina Display . That is the original iPad ran iOS 3.2, which did not have the scale property. If you are targeting that far back you'll need to consider this and assume you don't have a retina display if UIScreen does not respond to scale .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM