实现的步骤
几个要点:
statusBarHeight
,用来获取手机状态栏的高度(),调用wx.getSystemInfo
获取- 还有注意的,在写样式距离和大小时建议都用px,因小程序右边的胶囊也是用的px,不是rpx。
wx.getMenuButtonBoundingClientRect()
获取胶囊信息,用来计算 导航栏高度- 单个页面配置自定义导航,记得把基础库 调节到
2.8.0
之上, 仅支持微信客户端7.0.0
向上
官方链接:
- 自定义导航页面配置:navigationStyle
- 状态栏高度 wx.getSystemInfo()
- 胶囊 wx.getMenuButtonBoundingClientRect()
自定义导航 - 微信社区 - 推荐look
根据需求来设计(可以计算各种高度)
- 状态栏高度:
wx.getSystemInfo --> res.statusBarHeight
- 导航栏高度:
胶囊高度 + ( 胶囊距离顶部距离 - 状态栏高度) * 2
data:{
statusHeight: 0, //状态栏高度
navHeight: 0 //导航栏高度
}
/**
* 获取状态栏|导航栏高度,
*/
getStatusBarHeight: function(){
let capsule = wx.getMenuButtonBoundingClientRect() ; //胶囊信息
wx.getSystemInfo({
success(res) {
that.setData({
statusHeight: res.statusBarHeight,
navHeight: capsule.height + (capsule.top - res.statusBarHeight) * 2
})
}
})
},
<view class="status-height" style="height:{{ statusHeight }}px"> //状态栏
cc
</view>
<view class="nav-height" style="height:{{ navHeight }}px"> //导航栏
bb
</view>