专为480x960像素分辨率的设备设计的应用程序在480x1136设备上执行。在480x1136设备上运行时,我需要能够检测到真正的分辨率。遗憾的是,我没有获得设备分辨率('480x1136'),而是获得了应用分辨率(var len = pathOne.getTotalLength();
paper.customAttributes.along = function (v) {
var point = pathOne.getPointAtLength(v * len);
return {
transform: "t" + [point.x, point.y] + "r" + point.alpha
};
};
circle.attr({ along: 0 });
function animateThere( val ) {
val = +!val; // toggle
pathOne.click( function() { animateThere( val ) } );
circle.animate({ along: val }, 2000 );
};
pathOne.click( function() { animateThere(0) } );
),因此== '480x960'
返回[[UIScreen mainScreen] bounds].size * [[UIScreen mainScreen] scale]
而不是预期的'480x960'
如何解析真实的设备物理分辨率?
答案 0 :(得分: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
}
答案 1 :(得分: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;
}