在小程序開發中,涉及到適配iphonex的情況主要就是在頁面的最下出現button的情況,對於這個的解決思路就是:
1.獲取設備型號:
// 在app.js中判斷是否是哪種設備
globalData: {
isIphoneX: false,
userInfo: null
},
onShow:function(){
let that = this;
wx.getSystemInfo({
success: res=>{
// console.log('手機信息res'+res.model)
let modelmes = res.model;
if (modelmes.search('iPhone X') != -1) {
that.globalData.isIphoneX = true
}
}
})
},
2.根據不同的設備,設置不同的css樣式,另外在html布局的時候button放進別的容器標簽中例如:
xx.wxml
<view class='contentView' style='padding-bottom:{{btuBottom}}'>
<button class='but'>Button </button>
</view>
xx.js data: { btuBottom:""; }, //在這里只需要判斷是不是iphonex,然后設置下padding-bottom:即可 onLoad: function (options) { let isPhone = app.globalData.isIphoneX; if(isPhone){ this.setData({ btuBottom:"68rpx", }) } }
