以小游戏为示范,代码如下:
// 市面上已知的刘海屏机型(不全)
fringeScreenModels: [
"iPhone X", "iPhone x", "vivo X21A", "ASUS Zenfone 5",
"Ulefone T2 Pro", "Leagoo S9", "HUAWEI P20", "DooGee V",
"OPPO R15", "LG G7", "SAMSUNG S9", "COR-AL00",
"vivo Y83A", "LLD-AL20", "vivo Z1", "PACM00", "PAAM00"],
//是否有刘海屏
// 刘海手机里iphoneX系列刘海高度最高:60px,以最大值适配,若判断为刘海屏UI高度统一下调60px
hasScreenFringe: function () {
if (!this.systemInfo) {
this.systemInfo = wx.getSystemInfoSync();
}
if (this.systemInfo.model != null) {
for (let i in this.fringeScreenModels) {
if (this.systemInfo.model.indexOf(this.fringeScreenModels[i]) > -1) {
// 是已知机型里的刘海手机
return true;
}
}
}
// 屏幕宽高比大于2,基本上90%的手机可以确定是刘海屏,就算个别手机不是也按刘海屏处理
// 竖屏游戏判断:
if (this.systemInfo.windowHeight >= 800 || this.systemInfo.windowHeight / this.systemInfo.windowWidth > 2) {
return true;
}
// // 横屏游戏判断:
// if (this.systemInfo.windowWidth >= 800 || this.systemInfo.windowWidth / this.systemInfo.windowHeight > 2) {
// return true;
// }
return false;
},
网友评论