自学内容网 自学内容网

uniapp微信小程序解决上方刘海屏遮挡

问题

在有刘海屏的手机上,我们的文字和按钮等可能会被遮挡   应该避免这种情况

解决

const SYSTEM_INFO = uni.getSystemInfoSync();

export const getStatusBarHeight = ()=> SYSTEM_INFO.statusBarHeight || 15;

export const getTitleBarHeight = ()=>{
if(uni.getMenuButtonBoundingClientRect){
let {top,height} = uni.getMenuButtonBoundingClientRect();
return height + (top - getStatusBarHeight())*2
}else{
return 40;
}
}

export const  getNavBarHeight = ()=> getStatusBarHeight()+getTitleBarHeight();
import {getStatusBarHeight,getTitleBarHeight,getNavBarHeight} from "@/utils/system.js"

uni.getSystemInfoSync() 获取机型状态

uni.getMenuButtonBoundingClientRect() 获取胶囊按钮状态


getStatusBarHeight: 获取安全高度 状态栏高度

getTitleBarHeight:标题栏高度 胶囊按钮高度

getNavBarHeight:两者相加的(填充层)


原文地址:https://blog.csdn.net/zhuyuyaya/article/details/136233606

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!