收藏
回答

小程序建议可以获取titleBar高度的需求。

做自定义导航栏用。

需要获取用户机型导航栏高度。


wx.getSystemInfo({

      success: (res) => {

        // let totalTopHeight = (wx.getMenuButtonBoundingClientRect().bottom + wx.getMenuButtonBoundingClientRect().top) - (res.statusBarHeight * 2)

        // this.globalData.statusBarHeight = res.statusBarHeight

        // this.globalData.titleBarHeight = totalTopHeight

        // console.log(wx.getMenuButtonBoundingClientRect())   //真机上top 和 bottom 少2px 开发者工具正常。该方法拿到的高度在iPad上还是无法做到适配。


//该方法不兼容安卓刘海屏。

        let totalTopHeight = 68

        if (res.model.indexOf('iPhone X') !== -1) {

          totalTopHeight = 88

        } else if (res.model.indexOf('iPhone') !== -1) {

          totalTopHeight = 64

        }

        this.globalData.statusBarHeight = res.statusBarHeight

        this.globalData.titleBarHeight = totalTopHeight - res.statusBarHeight

        console.log(this.globalData.statusBarHeight)

        console.log(this.globalData.titleBarHeight)

      },

      fail: () => {

        this.globalData.statusBarHeight = 20

        this.globalData.titleBarHeight = 44

      }

    })



迫切的希望能通过api拿到titleBarHeight:也就是这块区域的高度。用胶囊位置去算 真机上top 和 bottom 少2px;



代码片段如下:https://developers.weixin.qq.com/s/wi6Pglmv7s8P。




回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容