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引用
本文介绍了一种通过小程序API获取屏幕安全区域信息的方法,并利用这些信息判断当前设备是否为iPhoneX。通过修改app.js中的全局变量来实现不同页面对iPhoneX状态的引用。
1万+

被折叠的 条评论
为什么被折叠?



