您的位置:首页 > 产品设计 > UI/UE

air开发中的requestedDisplayResolution 扫盲

2013-12-05 14:47 211 查看
app.xml里面requestedDisplayResolution 取值可以为high/standard, 如果为high表示设备跟ios声明它需要使用高清屏(其实就是需要最大分辨率)

这里我猜测了一下ios对这个参数的解释,伪代码如下:

if ( device.hasHighResolutionDisplay) { //设备是否具备高清屏
if (app.requestedDisplayResolution == "high"  ) {
app.stageWidth = device.maxResolution.x;
app.stageHeight = device.maxResolution.y;
device.renderAppScale(1); // 以scale=1的正常尺寸渲染整个APP
} else {
app.stageWidth = device.maxResolution.x/2;
app.stageHeight = device.maxResolution.y/2;
device.renderAppScale(2); // 以scale=2的放大尺寸渲染整个APP, 实际上就是4个像素点渲染原APP一个像素点
}

} else {
app.stageWidth = device.maxResolution.x;
app.stageHeight = device.maxResolution.y;
device.renderAppScale(1); // 以scale=1的正常尺寸渲染整个APP
}


下面是目前的苹果设备在不同的requestedDisplayResolution下的屏幕显示情况

stageWidth*stageHeight

设备 requestedDisplayResolution=high requestedDisplayResolution=standard

iphone4/4s 640*960 320*480

iphone5 640*1136 320*480

ipad1/2/mini 768*1024 768*1024

ipad3/4 1536*2048 768*1024

如果我们是以640*960的尺寸为标准开发的IOS程序,设置requestedDisplayResolution为high, 为了让我们的程序在所有IOS设备上都能正常显示,还需要:

1. 假设我们没有使用starling, , 假设我们的程序所有的UI都放置在某个根节点root下,那么,在iphone 3gs下设置root.scaleX = scaleY = 0.5, 在ipad3/4上设置root.scaleX = root.scaleY = 2, (当然,ipad上会有黑边,假设这个可以忍受,或者可以继续缩放到只有一边黑边)。

2. 假设我们使用了starling, 那么在starling构造函数里,先传入640*960的viewport, 然后在iphone 3GS里额外设置 viewPort = new Rectangle(0, 0, 320, 480), 在ipad 3/4上额外设置 viewPort=new Rectangle(0,0, 1536, 2048).

在ipad3/4上做了2倍的放大, 在方案1里会极大影响air的渲染性能

那么我们可以采取另外一套方法, 在ipad3/ipad4里设置requestedDisplayResolution=standard, 这样就不需要额外做缩放了, 而ios在Ipad3/4上会自动的放大整个程序为2倍大小。

这样带来的另外一个问题是, 我们想发布一次ipa就能兼容所有的设备, 幸好 adobe air 3.6最新beta版本带来了这个属性, 只需要加入这个参数:

<requestedDisplayResolution  excludeDevices="iPad3 iPad4">high</requestedDisplayResolution>


那么在Ipad3, ipad4上将默认使用requestedDisplayResolution =standard
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: