小程序页面使用“navigationStyle“:“custom“之后手动加标题的方法(判断机型)

小程序页面使用"navigationStyle":"custom"之后手动加标题的方法
手动定位上去

下面这个方法可以获取状态栏高度和导航栏高度以及机型
uni.getSystemInfo({
      success: (e) => {
        let statusBar = 0   // statusBar ---------- 状态栏高度
        let navBar = 0   // statusBar ---------- 状态栏高度
        let customBar = 0   // customBar -------- 状态栏高度 + 导航栏高度
        
        
        // #ifdef MP
        statusBar = e.statusBarHeight
        customBar = e.statusBarHeight + 45
        if (e.platform === 'android') {
          customBar = e.statusBarHeight + 50
        }
        // #endif
        
        
        // #ifdef MP-WEIXIN
        statusBar = e.statusBarHeight
        // @ts-ignore
        const custom = wx.getMenuButtonBoundingClientRect()
        customBar = custom.bottom + custom.top - e.statusBarHeight
        // #endif
  
  
        // #ifdef MP-ALIPAY
        statusBar = e.statusBarHeight
        customBar = e.statusBarHeight + e.titleBarHeight
        // #endif
  
  
        // #ifdef APP-PLUS
        console.log('app-plus', e)
        statusBar = e.statusBarHeight
        customBar = e.statusBarHeight + 45
        // #endif
  
  
        // #ifdef H5
        statusBar = 0
        customBar = e.statusBarHeight + 45
        // #endif
        
        navBar = customBar-statusBar
        this.statusBar = statusBar
        this.customBar = customBar
        this.navBar = navBar
        
        if ((e.model.search('iPhone X') !== -1 || e.model.search('iPhone 11') !== -1 || e.model.search('iPhone 12'))!=-1) {
          this.isIphoneAdaptation = true
          if(this.isIphoneAdaptation){
            this.titleHeight = 170
          }
        }        
      }
    })

版权声明:本文为qq_44706619原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。