当前位置:   article > 正文

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

uniapp 刘海屏

问题

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

解决

  1. const SYSTEM_INFO = uni.getSystemInfoSync();
  2. export const getStatusBarHeight = ()=> SYSTEM_INFO.statusBarHeight || 15;
  3. export const getTitleBarHeight = ()=>{
  4. if(uni.getMenuButtonBoundingClientRect){
  5. let {top,height} = uni.getMenuButtonBoundingClientRect();
  6. return height + (top - getStatusBarHeight())*2
  7. }else{
  8. return 40;
  9. }
  10. }
  11. export const getNavBarHeight = ()=> getStatusBarHeight()+getTitleBarHeight();
import {getStatusBarHeight,getTitleBarHeight,getNavBarHeight} from "@/utils/system.js"

uni.getSystemInfoSync() 获取机型状态

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


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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/143950
推荐阅读
相关标签
  

闽ICP备14008679号