实际效果
使用
//使用
let posConfig = this.getPosConfig(); // 传false返回值为 px大小
console.log(posConfig.safeBottomH)
// 入参 是否转换为rpxgetPosConfig(toRpx = true) {const systemInfo = uni.getSystemInfoSync();// #ifdef MPconst menuButtonInfo = uni.getMenuButtonBoundingClientRect();// #endifconst posConfig = {statusBarH: systemInfo.statusBarHeight,//状态栏高度tabBarH: systemInfo.screenHeight - systemInfo.windowHeight,//底部tab高度safeBottomH: systemInfo.safeAreaInsets.bottom,//底部安全高度// #ifdef MPcapsuleH: menuButtonInfo.height, //胶囊高度capsuleW: menuButtonInfo.width, //胶囊宽度capsuleGap: menuButtonInfo.top - systemInfo.statusBarHeight, // 胶囊到状态栏的间隔customBarH: menuButtonInfo.height + (menuButtonInfo.top - systemInfo.statusBarHeight) * 2, //自定义导航栏高度customBarW: menuButtonInfo.left, // 自定义导航栏宽度// #endif}if (toRpx) {const ratio = 750 / systemInfo.windowWidth;for (let key in posConfig) {posConfig[key] *= ratio;}}return posConfig;
}