uniapp或微信小程序底栏固定定位在小黑条下全面屏适配解决

文章介绍了如何在uniapp和微信小程序中利用uni.getSystemInfo和wx.getSystemInfoAPI获取安全区域信息,特别是safeAreaInsets和safeArea参数。通过封装getSafeAreaInsets函数,可以在页面加载时动态设置底部栏的padding,以适应全面屏的安全区域。作者提供了一个实例,展示如何调整底部栏的样式来避免被底部黑线遮挡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用uni或者微信提供的api uniapp开发者文档

 微信小程序微信开发者文档

 uni使用safeAreaInsets参数

微信使用safeArea参数

/**
 获取到屏幕的安全区域
 全面屏的值为to顶部状态栏和bottom底部黑线安全区
 */
export function getSafeAreaInsets() {
	let safeAreaInsets = 0
	uni.getSystemInfo({
		success: function (res) {
			console.log(res.model);
			console.log(res.pixelRatio);
			console.log(res.windowWidth);
			console.log(res.windowHeight);
			console.log(res.language);
			console.log(res.version);
			console.log(res.platform);
			console.log(res.safeAreaInsets)
			console.log(res)
			safeAreaInsets = res.safeAreaInsets

		}
	})
	return safeAreaInsets
}

封装一个工具,哪个页面用哪里就调用,微信小程序把uni. 换成wx. 就行

下面是我的底栏html代码,绑定一个动态的style属性

 data里声明变量padding:'padding-bottom:0'

下面是页面加载时调用,我这里直接使用他返回的bottom值感觉有点大,我自己减去了10,大家可以自己调整

onLoad: function (option) {
		let safeBottom = getSafeAreaInsets().bottom
		if(safeBottom > 0){
			this.padding = 'padding-bottom:'+(safeBottom-10)*2+'rpx'
		}
		console.log(this.padding)
	},

然后就搞定了

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

红烧Jay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值