小程序适配IOS底部小黑条

news/2024/7/20 2:39:10 标签: 小程序, ios

1、IOS底部小黑条高34px进行适配

<view class="container-px" style="padding-bottom: {{isIOS ? '68rpx' : 0}};">
  <view class="container-wrap"></view>
</view>

2、使用css

兼容ios<11.2
padding-bottom: constant(safe-area-inset-bottom); 底部安全区域812 - 778 = 34
兼容ios>11.2
padding-bottom: env(safe-area-inset-bottom);
env() 跟 constant() 需要同时存在,而且顺序不能换

<view class="container-css-fit">
  <view class="container-wrap"></view>
</view>
.container-css-fit{
  box-sizing: border-box;
  width: 100%;
  height: 100vh;
  /* 兼容ios<11.2 */
  padding-bottom: constant(safe-area-inset-bottom);  /* 底部安全区域812 - 778 = 34*/
  /* 兼容ios>11.2 */
  padding-bottom: env(safe-area-inset-bottom);
  /* env() 跟 constant() 需要同时存在,而且顺序不能换 */
}
.container-wrap{
  width: 100%;
  height: 100%;
  background-color: plum;
}

3、使用getSystemInfoSync计算安全区域

<view class="container-system" style="{{result.bottomSafeHeight ? ('padding-bottom: ' + result.bottomSafeHeight + 'px') : ''}}">
  <view class="container-wrap"></view>
</view>

const res = wx.getSystemInfoSync()
const result = {
…res,
bottomSafeHeight: 0,
isIphoneX: false,
isMi: false,
isIphone: false,
isIpad: false,
isIOS: false,
isHeightPhone: false,
}
const modelmes = result.model
const system = result.system
// 判断设备型号
if (modelmes.search(‘iPhone X’) != -1 || modelmes.search(‘iPhone 11’) != -1) {
result.isIphoneX = true;
}
if (modelmes.search(‘MI’) != -1) {
result.isMi = true;
}
if (modelmes.search(‘iPhone’) != -1) {
result.isIphone = true;
}
if (modelmes.search(‘iPad’) > -1) {
result.isIpad = true;
}
let screenWidth = result.screenWidth
let screenHeight = result.screenHeight
// 宽高比自适应
screenWidth = Math.min(screenWidth, screenHeight)
screenHeight = Math.max(screenWidth, screenHeight)
const ipadDiff = Math.abs(screenHeight / screenWidth - 1.33333)
if (ipadDiff < 0.01) {
result.isIpad = true
}
if (result.isIphone || system.indexOf(‘iOS’) > -1) {
result.isIOS = true
}
const myCanvasWidth = (640 / 375) * result.screenWidth
const myCanvasHeight = (1000 / 667) * result.screenHeight
const scale = myCanvasWidth / myCanvasHeight
if (scale < 0.64) {
result.isHeightPhone = true
}
result.navHeight = result.statusBarHeight + 46
result.pageWidth = result.windowWidth
result.pageHeight = result.windowHeight - result.navHeight
if (!result.isIOS) {
result.bottomSafeHeight = 0
}
const capsuleInfo = wx.getMenuButtonBoundingClientRect() // 获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点
// 胶囊热区 = 胶囊和状态栏之间的留白 * 2 (保持胶囊和状态栏上下留白一致) * 2(设计上为了更好看) + 胶囊高度
const navbarHeight = (capsuleInfo.top - result.statusBarHeight) * 4 + capsuleInfo.height
// 写入胶囊数据
result.capsuleInfo = capsuleInfo;
// 安全区域
const safeArea = result.safeArea
// 可视区域高度 - 适配横竖屏场景
const height = Math.max(safeArea.height, safeArea.width)
// 状态栏高度
const statusBarHeight = result.statusBarHeight
// 获取底部安全区域高度(全面屏手机)
if (safeArea && height && screenHeight) {
result.bottomSafeHeight = screenHeight - height - statusBarHeight
if (result.bottomSafeHeight < 0) {
result.bottomSafeHeight = 0
}
}
// 设置header高度
result.headerHeight = statusBarHeight + navbarHeight
// 导航栏高度
result.navbarHeight = navbarHeight


http://www.niftyadmin.cn/n/5321383.html

相关文章

用通俗易懂的方式讲解:如何用大语言模型构建一个知识问答系统

传统搜索系统基于关键字匹配&#xff0c;在面向&#xff1a;游戏攻略、技术图谱、知识库等业务场景时&#xff0c;缺少对用户问题理解和答案二次处理能力。 本文探索使用大语言模型&#xff08;Large Language Model, LLM&#xff09;&#xff0c;通过其对自然语言理解和生成的…

Kubernetes实战(十六)-k8s节点打标签

pod可以根据调度策略让pod调度到想要的节点上运行&#xff0c;或者不在某节点运行。 1 查看现有节点运行环境已有标签 $ kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS ops-master-1 Ready control-plane,ma…

恒通未来-大数据传输中的WDM解决方案

DWDM的出现是光纤传输技术发展中最新的重要现象之一。本教程将介绍DWDM技术的基本原理&#xff0c;如组件、DWDM系统中使用的光放大器等。 组件和操作&#xff1a; DWDM是光传输网络中的一种核心技术。DWDM的基本组件可以根据其在系统中的位置进行分类。在发射方面&#xff0…

uniapp使用checkbox-group以及API

在Uniapp中&#xff0c;我们可以使用checkbox-group组件来实现多选框的功能。该组件可以将多个checkbox绑定在一起&#xff0c;使得它们可以一起被操作。 首先&#xff0c;在页面中引入checkbox-group组件&#xff1a; <checkbox-group v-model"selectedFruits"&…

瑞吉外卖笔记系列(2) —— 完善员工的后台系统登录功能,实现员工信息管理

本文档主要 完善员工的后台系统登录功能&#xff0c;新增员工&#xff0c;员工信息分页查询&#xff0c;启用/禁用员工账号&#xff0c;编辑员工信息 一、完善后台系统登录功能 1.1 问题分析 目前存在的问题是&#xff1a;理论上&#xff0c;用户必须在 http://localhost:808…

MOE介绍 混合专家模型

GShard arxiv链接 GShard 模型架构图&#xff1a; 参考GShard论文笔记&#xff08;1&#xff09;-MoE结构可知&#xff0c;MOE具备以下几种特点&#xff1a; 改造了原本的FFN层&#xff0c;变成Gaten个FFN层。n个FFN层的训练数据集不同。推理时会计算token与每个FFN的匹配…

postgresql迁移到mysql

1.工具方法&#xff1a;Navicat Premium16 2. 手工方法&#xff1a; 迁移流程 下面是将 Postgresql 数据库迁移到 MySQL 的步骤流程&#xff1a; 步骤描述1. 创建MySQL表结构在MySQL中创建与Postgresql中的表结构相同的表2. 导出Postgresql数据将Postgresql中的数据导出为SQ…

Linux从入门到精通(第14章 传输文件)

如何在Ubuntu上安装配置NFS_ubuntu 安装nfs-CSDN博客 遇到某些问题&#xff1a; 1、无权限更改文件&#xff1a;sudo -s 2、sudo ifconfig无法识别&#xff1a;sudo apt-get install net-tools 最后的效果是&#xff1a; 在服务端的机器上&#xff1a;rootsword:/nfs_shar…