How can I detect the dpi on an ipad mini?

被刻印的时光 ゝ 提交于 2019-11-29 14:43:28

问题


I've got an ipad app with some pretty small touch points that are just barely acceptable on the 10 inch screen of a normal ipad. I'd like to be able to get the device dpi so I can scale up the size of the small elements for the mini and whatever future mini's that are released.


回答1:


The DPI is 163 pixels per inch (ppi):

http://www.apple.com/ipad-mini/specs/

You cannot get this programmatically, so you will need to store as a constant in your code.




回答2:


You cannot get the dpi (or more correctly ppi) value directly, because you have to know the number of milimeters (or inches) of the physical screen.
You first have to detect whether it is an iPad mini or not, and then you store the dpi value for each (yet known) device in your app.

As time of writing, this code detects iPad mini:

#include <sys/utsname.h>
NSString *machineName()
{
    struct utsname systemInfo;
    if (uname(&systemInfo) < 0) {
        return nil;
    } else {
        return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];
    }
}

// detects iPad mini by machine id
+ (BOOL) isIpadMini {

    NSString *machName = machineName();
    if (machName == nil) return NO;

    BOOL isMini = NO;
    if (    [machName isEqualToString:@"iPad2,5"]
         || [machName isEqualToString:@"iPad2,6"]
         || [machName isEqualToString:@"iPad2,7"])
    {
        isMini = YES;
    }
    return isMini;
}

It's not futureproof because a new machine id might be introduced later, but there is no futureproof method.
If it is an iPad mini use 163 dpi, otherwise use the links above in the comment, to calculate dpi for iPhone and iPad.



来源:https://stackoverflow.com/questions/13178186/how-can-i-detect-the-dpi-on-an-ipad-mini

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!