小程序适配IOS底部小黑条

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

xml 复制代码
<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() 需要同时存在,而且顺序不能换

xml 复制代码
<view class="container-css-fit">
  <view class="container-wrap"></view>
</view>
css 复制代码
.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计算安全区域

xml 复制代码
<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

相关推荐
说私域1 小时前
移动互联网生态下定制开发开源AI智能名片S2B2C商城小程序源码在营销技术中的应用与发展
人工智能·小程序·开源
微爱帮监所写信寄信2 小时前
微爱帮监狱写信寄信工具服务器【Linux篇章】再续:TCP协议——用技术隐喻重构网络世界的底层逻辑
linux·服务器·开发语言·网络·网络协议·小程序·监狱寄信
TheNextByte14 小时前
如何安全有效地清除iPad数据以便出售?
安全·ios·ipad
微爱帮监所写信寄信5 小时前
微爱帮监狱写信寄信小程序:MySQL核心日志与备份恢复安全架构
数据库·mysql·小程序·邮局·监狱寄信·挂号信·邮政
十二测试录5 小时前
Android和iOS测试区别
android·经验分享·ios·职场发展·ab测试
Z单单6 小时前
微信小程序订单信息录入路径设置
微信小程序·小程序
码界奇点7 小时前
基于Spring Boot和微信小程序的小程序商城系统设计与实现
spring boot·微信小程序·小程序·毕业设计·源代码管理
微爱帮监所写信寄信8 小时前
微爱帮监狱寄信写信小程序:深入理解JavaScript中的Symbol特性
开发语言·javascript·网络协议·小程序·监狱寄信·微爱帮
张飞签名上架8 小时前
深耕全球市场:App上架iOS与Google Play全流程指南
macos·ios·cocoa·ios上架·上架·谷歌上架
计算机毕设指导68 小时前
基于微信小程序的智慧社区娱乐服务管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·娱乐