函数:getScreenSize 获取屏幕分辨率
函数名称:获取屏幕分辨率,取分辨率
函数功能:用于获取设备屏幕的分辨率,用来判断坐标系的使用。
函数方法
w,h = getScreenSize();
必填
无
选填
无
返回值
返回值 | 类型 | 说明 |
---|---|---|
w | number | 获取到的屏幕宽度 |
h | number | 获取到的屏幕高度 |
函数用例
根据分辨率判断脚本是否适配
w,h = getScreenSize();
if w == 640 and h == 1136 then --iPhone SE,5,5S,iPod touch 5
nLog("iPhone SE,5,5S, iPod touch 5")
elseif w == 640 and h == 960 then --iPhone 4,4S,iPod touch 4
nLog("iPhone 4,4S,iPod touch 4")
elseif w == 320 and h == 480 then --iPhone 非高分屏
nLog("iPhone 非高分屏")
elseif w == 768 and h == 1024 then --iPad 1,2,mini 1
nLog("iPad 1,2,mini 1")
elseif w == 1536 and h == 2048 then --iPad 3,4,5,mini 2
nLog("iPad 3,4,5,mini 2")
elseif w == 1080 and h == 1920 then
nLog("小米 4,华为荣耀 6p 等")
elseif w == 720 and h == 1280 then
nLog("红米 note2 等")
elseif w == 768 and h == 1280 then
nLog("魅蓝等")
elseif w == 800 and h == 1280 then
nLog("三星 N5100 等")
elseif w == 480 and h == 800 then
nLog("酷派 8017-T00 等")
end
注意事项
统一为 iOS 竖屏(Home 键在下方时)、安卓初始方向屏幕的宽度和高度。
部分安卓设备存在无法获取到屏幕分辨率的问题,需要在脚本中判断:如果返回值小于 0,则指定一个固定的宽高。