小程序适配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

相关推荐
正小安4 小时前
如何在微信小程序中实现分包加载和预下载
前端·微信小程序·小程序
说私域4 小时前
基于定制开发与2+1链动模式的商城小程序搭建策略
大数据·小程序
工业互联网专业12 小时前
毕业设计选题:基于ssm+vue+uniapp的校园水电费管理小程序
vue.js·小程序·uni-app·毕业设计·ssm·源码·课程设计
missmisslulu14 小时前
电容笔值得买吗?2024精选盘点推荐五大惊艳平替电容笔!
学习·ios·电脑·平板
GEEKVIP15 小时前
手机使用技巧:8 个 Android 锁屏移除工具 [解锁 Android]
android·macos·ios·智能手机·电脑·手机·iphone
说私域15 小时前
社群团购中的用户黏性价值:以开源小程序多商户AI智能名片商城源码为例
人工智能·小程序
GEEKVIP15 小时前
如何在 Windows 10 上恢复未保存/删除的 Word 文档
macos·ios·智能手机·电脑·word·笔记本电脑·iphone
奇客软件16 小时前
iPhone使用技巧:如何恢复变砖的 iPhone 或 iPad
数码相机·macos·ios·电脑·笔记本电脑·iphone·ipad
迷雾yx19 小时前
开发微信小程序 基础02
微信小程序·小程序
迷雾yx19 小时前
开发微信小程序 基础03
微信小程序·小程序