iphoneX真机测试图:
Demo是横屏的,竖屏自行类推
var DesignWidth = 1334;
var DesignHeight = 750;
cc.Class({
extends: cc.Component,
onLoad: function () {
// 设置适配模式(横屏)
if(cc.sys.OS_ANDROID == cc.sys.os || cc.sys.OS_IOS == cc.sys.os) {
if((cc.view.getFrameSize().width / cc.view.getFrameSize().height) == (2436 / 1125)){
this.isIphoneX = true;
}else{
this.isIphoneX = false;
}
if((cc.view.getFrameSize().width / cc.view.getFrameSize().height) >= (DesignWidth / DesignHeight)){
//宽度超出
var width = cc.view.getFrameSize().width * (DesignHeight / cc.view.getFrameSize().height);
cc.view.setDesignResolutionSize(width, DesignHeight, cc.ResolutionPolicy.FIXED_HEIGHT);
}else{
//高度超出
var height = cc.view.getFrameSize().height * (DesignWidth / cc.view.getFrameSize().width);
cc.view.setDesignResolutionSize(DesignWidth, height, cc.ResolutionPolicy.FIXED_WIDTH);
}
}else{
cc.view.setDesignResolutionSize(DesignWidth, DesignHeight, cc.ResolutionPolicy.EXACT_FIT);
}
if(this.isIphoneX){
cc.find("Canvas/other/user1").getComponent(cc.Widget).left += this.node.width * (44/812);
cc.find("Canvas/other/user2").getComponent(cc.Widget).left += this.node.width * (44/812);
}
},
});
截图都是用的模拟器
分辨率:19201080
分辨率:1500750
fenbi
分辨率:2436*1125
分辨率:1920*1600
DEMO下载地址:
fitScreenDemo.zip (353.7 KB)





