uniapp h5 tabBar兼容IOS手机底部黑线

阅读: 评论:0

uniapp h5 tabBar兼容IOS手机底部黑线

uniapp h5 tabBar兼容IOS手机底部黑线

uniapp 兼容IOS手机底部黑线 IOS苹果手机有很多款手机底部都有一条黑线。底部的tabbar 导航栏如果遇到IOS手机则会出现问题。 因为我这边的tabbar导航栏是自己写的,不是用的uniapp自带的,所以如果遇到IOS手机底部有黑线的这种,需要将tabbar导航栏的高度调整一下才可以。 除此之外还有些页面,底部有个按钮之类的,也是需要做兼容处理的。

uni-app:iPhone的底部安全区域

padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
Systeminfo({success: res => {let safeArea = res.safeAreaInsets.bottom;}
})

该APi返回一个对象,包含 top right bottom left width height,其中bottom为安全区域高度

对应的兼容情况如下,uni-app的版本2.5.3+使用safeAreaInsets值

safeArea 在竖屏正方向下的安全区域 App、H5、微信小程序
safeAreaInsets 在竖屏正方向下的安全区域插入位置(2.5.3+) App、H5、微信小程序

uniapp自定义tabBar方案

一、pages.json文件中添加tarBar

二、把原生的tabBar隐藏起来

三、自定义一个tabBar组件

        //重点代码

        height: 50px;
        padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
        padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/

<template><view class="tab-bar"><viewv-for="(item, index) in list":key="index"class="tab-bar-item"@click="switchTab(item, index)"><imageclass="tab_img":src="selected === index ? item.selectedIconPath : item.iconPath"></image><view class="tab_text" :style="{ color: selected === index ? selectedColor : color }">{{  }}</view></view></view>
</template><script>
export default {props: {selected: {// 当前选中的tab indextype: Number,default: 0}},data() {return {color: '#A1A1A1',selectedColor: '#F8A400',list: [{pagePath: '/pages/pointsMall/pointsMall',text: '商城',iconPath: '/static/tab_icons/cate.png',selectedIconPath: '/static/tab_icons/cate-active.png'},{pagePath: '/pages/mine/mine',text: '我的',iconPath: '/static/tab_icons/my.png',selectedIconPath: '/static/tab_icons/my-active.png'}]};},methods: {switchTab(item, index) {console.log('item', item);console.log('index', index);Launch({url: item.pagePath});}}
};
</script><style lang="scss">
.tab-bar {position: fixed;bottom: -1px;left: 0;right: 0;background-color: transparent;display: flex;justify-content: center;align-items: center;border-top-right-radius: 20px;.tab-bar-item {height: 50px;padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/background: white;flex: 1;text-align: center;display: flex;justify-content: center;align-items: center;flex-direction: row;.tab_img {width: 50rpx;height: 50rpx;}.tab_text {font-size: 20rpx;margin-left: 9rpx;}}
}
.tab-bar-item:first-child {border-top-right-radius: 20px;
}
.tab-bar-item:last-child {border-top-left-radius: 20px;
}
</style>

四、引用组件

五、路由跳转

本文发布于:2024-01-30 18:25:01,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170661030221950.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:黑线   手机   uniapp   IOS   tabBar
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23