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

问题

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

解决

javascript 复制代码
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();
javascript 复制代码
import {getStatusBarHeight,getTitleBarHeight,getNavBarHeight} from "@/utils/system.js"

uni.getSystemInfoSync() 获取机型状态

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


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

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

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

相关推荐
一份执念15 小时前
uni-app项目 (vue+vite + uni-UI)中引入umd格式JS文件,微信小程序中导入报错处理方案
前端·uni-app·echarts
PedroQue9921 小时前
V1.6.1性能优化:高频路径提速与代码精简
前端·uni-app
夏碧笔3 天前
uni-app跨端地图实战:用第三方LBS替代微信平台收费服务
uni-app
用户6990304848758 天前
try catch使用场景 处理同步代码错误兼容用的
javascript·uni-app
ITKEY_8 天前
uniapp微信开发者工具 更改AppID失败 touristappid
uni-app
Geek_Vison8 天前
APP瘦身实战:从80MB+砍到15MB——基于小程序容器技术剥离APP非核心业务的实践分享
小程序·uni-app·mpaas
CHB9 天前
HDC2026 演讲实录|AI 驱动的跨端进化:利用 uni-agent 快速构建高性能鸿蒙应用
uni-app·harmonyos
2501_915918419 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
斯内普吖9 天前
(开源)高校素拓分管理系统小程序实战指南 基于 Java + SpringBoot + uni-app + Vue + MySQL
java·spring boot·mysql·小程序·uni-app·开源
海阔天空66889 天前
uniapp开启调试模式
uni-app·uniapp开启调试模式