小程序根据手机机型设置自定义底部导航距离

需求:
iponeX 以上机型,手机底部有弧度,自己写的导航栏会被遮住, 需要判断手机机型,做兼容设置.
解决:

//app.js
App({
    onLaunch: function() {
        var that = this;
        //获取手机型号
        wx.getSystemInfo({
            success(res) {
                const model = res.model;
                const modelInclude = ["iPhone X", 'iPhone XR', "iPhone XS", "iPhone XS MAX"];
                var flag = false;//是否X以上机型
                for (let i = 0; i < modelInclude.length;i ++){
                	//模糊判断是否是modelInclude 中的机型,因为真机上测试显示的model机型信息比较长无法一一精确匹配
                    if (model.indexOf(modelInclude[i]) != -1){
                        flag = true
                    }
                }
                if (flag) {
                    that.BOTTOM_DISTANCE = 50; // 可手动更改底部高度
                }
            }
        })
    },
    BOTTOM_DISTANCE:0,//iponeX底部需要抬高的距离
})

页面js

const app = getApp();

Page({
    data: {
        bottom: app.BOTTOM_DISTANCE//将app实例中的BOTTOM_DISTANCE转化为页面的data,即可在xml上使用
    }
})

然后设置导航底部padding距离即可;
style='padding-bottom:{{bottom}}rpx'

<!-- 底部菜单 -->
   <view class='footer bg-white' style='padding-bottom:{{bottom}}rpx'>
        <view class='nav'>
            <navigator class='icon-img' hover-class="none" open-type="redirect" url="/pages/store/details?store_id={{store_id}}">
                <image class='img' src='../img/income/store/store-bar.png'></image>
            </navigator>
            <text>门店</text>
        </view>
        <view class='nav' bindtap='handleScan'>
            <view>
                <button class='icon-img' style='width:44rpx;height:44rpx;margin:6rpx'>
                    <image class='img' src='../img/income/home/saoma.png'></image>
                </button>
            </view>
            <text class='text-bar-red'>买单</text>
        </view>
        <view class='nav'>
            <navigator class='icon-img' style='width:46rpx;height:46rpx;margin:4rpx' hover-class="none" open-type="switchTab" url="/pages/user/user">
                <image class='img' src='../img/income/store/user.png'></image>
            </navigator>
            <text>我的</text>
        </view>
    </view>
</view>

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页