uniapp开发小程序,设置iphone底部安全区域

//app.vue
//设备信息
onLaunch: async function () {
    let app = uni.getSystemInfoSync();
    console.log('设备信息', app)
    let top = app.safeArea.top //屏幕顶部安全距离
    let height = app.safeAreaInsets.bottom //屏幕底部安全距离
}

//vux 保存上面获取到的两个变量
this.set_top(top);
this.set_safeAreaBottom(height);
 methods: {
    ...mapActions(['setLogined', 'removeLogined']),
    ...mapMutations(['set_safeAreaBottom', 'set_top'])
  },
//vuex
const store = new Vuex.Store({
    state: {
        safeAreaBottom: 0,
        top: 0,
    mutations: {
        set_safeAreaBottom (state, data) {
            state.safeAreaBottom = data
        },
        set_top (state, data) {
            state.top = data
        },
    },
    actions: {
       ....
    }
})
//这里dom结构我举个例子,仅供参考
<view class="safeArea" :style="{ 'padding-bottom': `${safeAreaBottom + 114}` + 'rpx' }">
  <view class="content">
  </view>
//底部
  <view class="flex justify-around bg-white" style="width:100%;height: 100rpx;">
  </view>
</view>

上面dom结构的,根据需求是这样的:整个屏幕被两个view占满,其中底部view是固定在底部不动的,content内容立马是高度盛满剩下屏幕高度,并且overflow:scorll ; safeArea里面的动态样式中的safeAreaBottom是vuex保存的值,后面加的114,是底部高度再略高一点:“100+14” ,其中14你给不给随意。

.safeArea {
  height: 100%;
  // padding-bottom: var(--safeAreaBottom);
}

.content {
  height: 100%;
  overflow-y: scroll;
}

写到这里就没啦~ 手机顶部的安全距离 等有需求碰到了我再过来详细记录~~ 值已经在上面获取到了,就是vuex保存的top变量的值。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

柑橘乌云_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值