当前位置: 首页 > news >正文

微信小程序 -- ios 底部小黑条样式问题

问题:

在这里插入图片描述
如图,ios有的机型底部伪home键会显示在按钮之上,导致点击按钮的时候误触

解决:

  1. App.vue
<script>export default {wx.getSystemInfo({success: res => {let bottomHeight = res.screenHeight - res.safeArea.bottom;uni.setStorageSync('bottomHeight', bottomHeight)console.log('小黑条高度', bottomHeight);},fail(err) {console.log(err);}})},}
</script><style>/*每个页面公共css */@import url("static/css/base.css");
</style>
  1. 有样式问题需要修改的页面

我这里写的是:如果不是有小黑条的机型(也就是bottomHeight===0的机型),那么我的paddingBottom设为10px;如果有的话,那么paddingBottom就设为小黑条的高度bottomHeight

<template><view @click="submit" :style="{paddingBottom:(bottomHeight===0?'10px':bottomHeight+'px')}"><view>提交</view></view>
</template><script>export default {data() {return {bottomHeight:0, // 底部小黑条高度}},onLoad() {this.bottomHeight = uni.getStorageSync('bottomHeight')||0;console.log('底部小黑条高度',this.bottomHeight)},}
</script><style scoped lang="scss">
</style>

效果图

在这里插入图片描述

参考

vue动态添加style样式

【对象】

html :style="{ color: activeColor, fontSize: fontSize + 'px' }"

html :style="{color:(index==0?conFontColor:'#000')}"

【数组】

html :style="[baseStyles, overridingStyles]"
html :style="[{color:(index==0?conFontColor:'#000')},{fontSize:'20px'}]"

【三目运算符】

html :style="{color:(index==0?conFontColor:'#000')}"
html :style="[{color:(index==0?conFontColor:'#000')},{fontSize:'20px'}]"

【多重值】
此时,浏览器会根据运行支持情况进行选择

html :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"

【绑定data对象】

  • html :style=“styleObject”
data() {return{styleObject: {color: 'red',fontSize: '13px'}  }
}

————————————————
原文:https://juejin.cn/post/6844903921509466120

小黑条适配

在移动端开发过程中,经常遇到iphone11、iphoneX底部小黑条遮挡页面底部,纯css实现设备的适配。详见我的上篇文章。

在开发微信小程序中,也会遇到iPhone全面屏手机,底部小黑条会遮挡页面底部,尽管微信小程序已经实现部分页面的适配,但个别页面仍旧需要做适配处理。

解决方案:使用wx.getSystemInfoSync()中的screenHeightsafeArea对象的bottom属性判断

  • screenHeight是获取屏幕的高度,因为bottom是以屏幕左上角为原点开始计算的,所以需要的是屏幕高度。

  • safeArea对象的bottom属性是安全区域右下角纵坐标。

  • screenHeight减去safeArea对象的bottom属性,则是底部小黑条的高度。

获取底部小黑条的高度,全局存储使用。

在全局app.js里,需要全局存储一个数据

globalData: {bottomHeight:0
}

2.在全局app.js的onLaunch函数:

wx.getSystemInfo({success: res => {this.globalData.bottomHeight = res.screenHeight - res.safeArea.bottom;},fail(err) {console.log(err);}
})

3.在所需页面的js文件从全局变量中获取

onLoad: function (options) {this.setData({bottomHeight : app.globalData.bottomHeight })}

4.在所需页面的wxml里面使用:

<view class="page" style="padding-bottom:{{bottomHeight }}px">

————————————————

原文链接:https://blog.csdn.net/u014213847/article/details/129159964

未整理参考

http://www.lryc.cn/news/258792.html

相关文章:

  • 白盒测试:探索软件内部结构的有效方法
  • 图论-并查集
  • redis-学习笔记(Jedis 通用命令)
  • C语言:高精度乘法
  • UE4 Niagara学习笔记
  • 多维时序 | Matlab实现GA-LSTM-Attention遗传算法优化长短期记忆神经网络融合注意力机制多变量时间序列预测
  • LeetCode205. Isomorphic Strings
  • Event Driven设计模式
  • PostgreSql 设置自增字段
  • 什么是泊松图像混合
  • OpenAI 承认 ChatGPT 最近确实变懒,承诺修复问题
  • 创作活动(四十九)———低代码:美味膳食或垃圾食品?
  • 【DL-TensorFlow遇错】TensorFlow中遇错合集
  • pymysql代替mysqlclient,解决mysqlclient因版本不兼容无法安装成功而无法连接mysql的问题
  • uni-app 设置当前page界面进入直接变为横屏模式
  • Mysql的多表联合查询
  • Linux上使用Python的requests库进行HTTP请求
  • 图像处理领域的应用
  • MySQL笔记-第18章_MySQL8其它新特性
  • C语言—每日选择题—Day46
  • flex布局,换行的元素上下设置间距
  • 【智能家居】八、监控摄像采集、人脸识别比对进行开门功能点
  • golang的文件操作
  • 数据库版本管理框架-Flyway(从入门到精通)
  • 外网访问内网服务器使用教程
  • C# Dictionary 利用 ContainsValue 查询指定值是否已经存在
  • 招不到人?用C语言采集系统批量采集简历
  • HXDSP2441-Demo板
  • 静态路由的原理和配置
  • Ubuntu20.04降低linux版本到5.4.0-26-generic