最近菜鸟做微信小程序,然后有一个图片置顶的功能

这个功能就需要把微信自带的导航栏样式给去掉,使用自定义导航栏样式,但是这个又产生一个问题,导航栏标题文字就不是很好适配了,因为不同手机型号,距离最上面的距离是不同的!
去掉导航栏的代码:
app.json
"window": {
"navigationStyle": "custom"
},
2023/6/1 补充(2024/1/4 改)
菜鸟突然发现,之前写的已经成为历史了,现在微信小程序可以通过 api 直接获取到这些高度,所以菜鸟在这里进行更新!
app.js的onLaunch加入下方代码:
// 获取胶囊的详细信息
let menuButtonObject = wx.getMenuButtonBoundingClientRect();
wx.getSystemInfo({
success: res => {
// 导航高度
let statusBarHeight = res.statusBarHeight,
// 胶囊距离顶部高度
navTop = menuButtonObject.top,
// 胶囊按钮与右侧的距离 = windowWidth - right + 胶囊宽度(包括右边距离)
navObjWid = res.windowWidth - menuButtonObject.right + menuButtonObject.width,
// 导航栏整体高度
navHeight = statusBarHeight + menuButtonObject.height + (navTop - statusBarHeight) * 2;
this.globalData.navHeight = navHeight;
this.globalData.navTop = navTop;
this