微信小程序安全区域适配问题

问题描述

在微信小程序开发过程中,有些页面的按钮是需要固定在页面底部(如电商详情页中的加入购物车按钮等),如果将底部栏样式直接设置为bottom:0;,那么在iPhone X、iPhone XR、iPhone 12等机型中,就会出现下图所示问题:按钮区域距离底部太近,可点击区域缩小,用户体验感差。

问题复现

安全区域适配问题

解决方案

方案一(最快速)

利用IOS新增的 env()constant() 特性即可解决,开发者不需要自己动态计算高度,只需将如下CSS代码添加至样式中:

示例代码:

<!-- 底部栏 -->
<view class="bottom"></view>
.bottom {
	position: fixed;
	bottom: 0;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
}

方案二(动态计算)

<!-- 底部栏 -->
<view class="bottom" style="padding-bottom:{{bottomPadding}}px"></view>
async onLoad() {
	const res = await wx.getSystemInfo({})
	const bottomPadding = res.screenHeight - res.safeArea.bottom
	this.setData({
	  bottomPadding
	})
}
.bottom {
	position: fixed;
	bottom: 0;
}
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

人人都在发奋

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

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

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

打赏作者

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

抵扣说明:

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

余额充值