0

为 480x960 像素分辨率的设备设计的应用程序在 480x1136 设备上执行。在 480x1136 设备上运行时,我需要能够检测到真实分辨率。不幸的是,我没有获得设备分辨率('480x1136'),而是获得了应用程序分辨率(== '480x960'),因此[[UIScreen mainScreen] bounds].size * [[UIScreen mainScreen] scale]返回'480x960'而不是预期'480x1136'

如何解决真实设备的物理分辨率?

4

2 回答 2

0
//Get device screen resolution for this specific case     

CGRect boundsOfScreen=[[UIScreen mainScreen] bounds];

        if (boundsOfScreen.size.width == 480 && boundsOfScreen.size.height == 960 ) {
            //iPod Touch 3.5-inch
        }
        else if (boundsOfScreen.size.width == 480 && boundsOfScreen.size.height == 1136) {
             //iPod Touch 4-inch
        }
于 2015-06-28T18:09:26.363 回答
0

这很丑,但是,这是我找到的唯一解决实际物理主显示分辨率的解决方案(独立于正在执行的应用程序):

#import <sys/utsname.h>

bool getDeviceNativeResolution(CGSize& res) {
    utsname si;
    uname(&si);

    if((0 == strncmp(si.machine, "iPod7", 5)) || (0 == strncmp(si.machine, "iPhone7", 7)))
        res = CGSizeMake(1080, 1920);
    else if((0 == strncmp(si.machine, "iPod6", 5)) || (0 == strncmp(si.machine, "iPhone6", 7)))
        res = CGSizeMake(750, 1334);
    else if((0 == strncmp(si.machine, "iPod5", 5)) || (0 == strncmp(si.machine, "iPhone5", 7)))
        res = CGSizeMake(640, 1136);
    else if((0 == strncmp(si.machine, "iPod4", 5)) || (0 == strncmp(si.machine, "iPhone4", 7)))
        res = CGSizeMake(640, 960);
    else
        return false;

    return true;
}
于 2015-06-29T06:16:03.420 回答