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:两者相加的(填充层)

相关推荐
2501_915921435 小时前
详细解析,iOS 应用上架 App Store 的完整流程与指南
android·ios·小程序·https·uni-app·iphone·webview
波罗丁牌21 小时前
uni-app 实现视频聊天、屏幕分享,支持Android、HarmonyOS、iOS
android·uni-app·音视频
前端l1 天前
uni‑app(Vue3+setup)开发微信小程序高频坑汇总
微信·uni-app
pan3035074791 天前
uniapp 不用发版也可以做到版本更新
uni-app
00后程序员张1 天前
使用Instruments工具深入分析iOS应用性能与启动时间优化
android·macos·ios·小程序·uni-app·cocoa·iphone
古韵1 天前
小程序上传进度条,还要自己监听 onProgressUpdate 吗?
前端·javascript·uni-app
不如摸鱼去2 天前
Wot UI 2.3.0 发布:二维码组件来了,Open Wot 与 wot-starter 同步更新
前端·ui·微信小程序·前端框架·uni-app
anyup2 天前
uni-app 没有根组件?仅需几行代码实现全局 Toast 和 Modal
前端·架构·uni-app
2501_916007472 天前
Python实现HTTPS爬虫的完整指南:使用requests、BeautifulSoup、Selenium和Scrapy
爬虫·python·ios·小程序·https·uni-app·iphone
AI_AGENT_DEV_AI2 天前
原生 APP(iOS / Android)的开发与上线
uni-app