1.在app.js内判断
App({
isIPhoneX: false, // 当前设备是否为 iPhone X
kBottomSafeHeight: 0, // X 34 ,其余 0
// 判断设备是否为 iPhone X
checkIsIPhoneX: function () {
var that = this
wx.getSystemInfo({
success: function (res) {
var safeBottom = res.screenHeight - res.safeArea.bottom
that.kBottomSafeHeight = safeBottom
//根据安全高度判断
if (safeBottom === 34) {
that.isIPhoneX = true
}
}
})
},
onLaunch() {
this.checkIsIPhoneX()
}
})
在其他页面直接使用app.kBottomSafeHeight引用