1、IOS底部小黑条高34px进行适配
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() 需要同时存在,而且顺序不能换
.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计算安全区域
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
猜你喜欢
- 11天前(安徽民宿发展报告)首届安徽省乡村民宿创意设计大赛启动
- 11天前(艾美酒店连锁)艾美酒店全球夏日计划回归,联手Wishbone主厨推出创新冰饮
- 11天前(甘肃文旅项目)甘肃省文旅产业链招商引资推介会在天水成功举办
- 11天前(天气预报 华为)2025HDC华为天气上新系统级天气智能体,引领更智能的气象服务
- 11天前(花王伴你乐享五一好“趣”处)花王伴你乐享五一好“趣”处
- 11天前(纳米比亚旅游报价)纳米比亚旅游局2024年中国推介会圆满落幕
- 11天前(中国最好的避暑山庄)2025中国十大避暑山庄评选揭晓,澳涞山庄夺魁
- 11天前(澳涞山庄见证北欧零碳到中国实践,世界十佳环境保护城市榜单发布)澳涞山庄见证北欧零碳到中国实践,世界十佳环境保护城市榜单发布
- 11天前(筑格集团有限公司)洲际酒店集团旗下筑格酒店品牌正式亮相大中华区
- 11天前(阿斯塔纳航空属于哪个联盟)阿斯塔纳航空荣获Skytrax世界航空公司大奖,将继续助力中哈交流往来
网友评论
- 搜索
- 最新文章
- (2020广州车展哈弗)你的猛龙 独一无二 哈弗猛龙广州车展闪耀登场
- (哈弗新能源suv2019款)智能科技颠覆出行体验 哈弗重塑新能源越野SUV价值认知
- (2021款全新哈弗h5自动四驱报价)新哈弗H5再赴保障之旅,无惧冰雪护航哈弗全民电四驱挑战赛
- (海南航空现况怎样)用一场直播找到市场扩张新渠道,海南航空做对了什么?
- (visa jcb 日本)优惠面面俱到 JCB信用卡邀您畅玩日本冰雪季
- (第三届“堡里有年味·回村过大年”民俗花灯会活动)第三届“堡里有年味·回村过大年”民俗花灯会活动
- (展示非遗魅力 长安启源助力铜梁龙舞出征)展示非遗魅力 长安启源助力铜梁龙舞出征
- (阿斯塔纳航空公司)阿斯塔纳航空机队飞机数量增至50架
- (北京香港航班动态查询)香港快运航空北京大兴新航线今日首航
- (我在港航“呵护”飞机 每一次安全着陆就是最好的荣誉)我在港航“呵护”飞机 每一次安全着陆就是最好的荣誉
- 热门文章