当前位置:   article > 正文

前端uniapp自定义tabbar,在iPoneX上,tabbar有个盒子用了绝对定位position: absolute被遮住问题,env(safe-area-inset-bottom)无效_uniapp苹果absolute失效

uniapp苹果absolute失效

出现问题前,是因为一个盒子我用了绝对定位position: absolute,在其他机型正常,在iPoneX上就出现问题

出现问题前代码

  1. <template>
  2. <view class="mian">
  3. <view class="box">
  4. <view class="sao">
  5. <view class="icon">
  6. <iconfont name="scan" size="50rpx" color="#fff"></iconfont>
  7. </view>
  8. <view class="name">扫一扫</view>
  9. </view>
  10. <view class="left">
  11. <view class="item">
  12. <view class="icon">
  13. <iconfont name="a-huiyuan1" size="45rpx"></iconfont>
  14. </view>
  15. <view>会员</view>
  16. </view>
  17. <view class="item">
  18. <view class="icon">
  19. <iconfont name="dingdan" size="45rpx"></iconfont>
  20. </view>
  21. <view>历史订单</view>
  22. </view>
  23. </view>
  24. <view class="right">
  25. <view class="item">
  26. <view class="icon">
  27. <iconfont name="shangpin" size="45rpx"></iconfont>
  28. </view>
  29. <view>订单</view>
  30. </view>
  31. <view class="item">
  32. <view class="icon">
  33. <iconfont name="yonghuming" size="45rpx"></iconfont>
  34. </view>
  35. <view>我的</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. aaa: 1
  46. }
  47. },
  48. computed: {
  49. },
  50. methods: {
  51. }
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .mian {
  56. position: fixed;
  57. left: 0;
  58. bottom: 0;
  59. background-color: #fff;
  60. height: 130rpx;
  61. width: 100%;
  62. box-shadow: 2rpx -4rpx 6rpx 0px #0000001a;
  63. font-size: 30rpx;
  64. padding:calc(env(safe-area-inset-bottom) + 15rpx) 0 calc(env(safe-area-inset-bottom) + 15rpx) 0;
  65. .box {
  66. width: 100%;
  67. height: 100%;
  68. display: flex;
  69. position: relative;
  70. align-items: center;
  71. justify-content: space-between;
  72. .sao {
  73. position: absolute;
  74. top: -45rpx;
  75. left: 315rpx;
  76. .icon {
  77. width: 130rpx;
  78. height: 130rpx;
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. border-radius: 50%;
  83. border: 15rpx solid #fff;
  84. box-shadow: 0px -2rpx 2rpx 0 #00000057;
  85. background-color: #0e67fe;
  86. }
  87. .name{
  88. text-align: center;
  89. }
  90. }
  91. .left,
  92. .right {
  93. width: 40%;
  94. height: 100%;
  95. display: flex;
  96. // flex-direction: column;
  97. justify-content: space-around;
  98. align-items: center;
  99. .item {
  100. width: 50%;
  101. display: flex;
  102. flex-direction: column;
  103. align-items: center;
  104. .icon {
  105. width: 50%;
  106. height: 100%;
  107. padding: 10rpx;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. // padding: 10rpx;
  112. margin-bottom: 5rpx;
  113. border: 2rpx solid #999;
  114. }
  115. }
  116. }
  117. }
  118. }
  119. </style>

解决问题后的效果

 解决问题需要算出距离top高度,top: calc(-1 * (env(safe-area-inset-bottom) + 55rpx)); 是其他机型正常显示的top加上iPhoneX高度*-1就好

解决后的代码

  1. <template>
  2. <view class="mian">
  3. <view class="box">
  4. <view class="sao">
  5. <view class="icon">
  6. <iconfont name="scan" size="50rpx" color="#fff"></iconfont>
  7. </view>
  8. <view class="name">扫一扫</view>
  9. </view>
  10. <view class="left">
  11. <view class="item">
  12. <view class="icon">
  13. <iconfont name="a-huiyuan1" size="45rpx"></iconfont>
  14. </view>
  15. <view>会员</view>
  16. </view>
  17. <view class="item">
  18. <view class="icon">
  19. <iconfont name="dingdan" size="45rpx"></iconfont>
  20. </view>
  21. <view>历史订单</view>
  22. </view>
  23. </view>
  24. <view class="right">
  25. <view class="item">
  26. <view class="icon">
  27. <iconfont name="shangpin" size="45rpx"></iconfont>
  28. </view>
  29. <view>订单</view>
  30. </view>
  31. <view class="item">
  32. <view class="icon">
  33. <iconfont name="yonghuming" size="45rpx"></iconfont>
  34. </view>
  35. <view>我的</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. aaa: 1
  46. }
  47. },
  48. computed: {
  49. },
  50. methods: {
  51. }
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .mian {
  56. position: fixed;
  57. left: 0;
  58. bottom: 0;
  59. background-color: #fff;
  60. height: 130rpx;
  61. width: 100%;
  62. box-shadow: 2rpx -4rpx 6rpx 0px #0000001a;
  63. font-size: 30rpx;
  64. padding:calc(env(safe-area-inset-bottom) + 15rpx) 0 calc(env(safe-area-inset-bottom) + 15rpx) 0;
  65. .box {
  66. width: 100%;
  67. height: 100%;
  68. display: flex;
  69. position: relative;
  70. align-items: center;
  71. justify-content: space-between;
  72. .sao {
  73. position: absolute;
  74. top: calc(-1 * (env(safe-area-inset-bottom) + 55rpx));
  75. left: 315rpx;
  76. .icon {
  77. width: 130rpx;
  78. height: 130rpx;
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. border-radius: 50%;
  83. border: 15rpx solid #fff;
  84. box-shadow: 0px -2rpx 2rpx 0 #00000057;
  85. background-color: #0e67fe;
  86. }
  87. .name{
  88. text-align: center;
  89. }
  90. }
  91. .left,
  92. .right {
  93. width: 40%;
  94. height: 100%;
  95. display: flex;
  96. // flex-direction: column;
  97. justify-content: space-around;
  98. align-items: center;
  99. .item {
  100. width: 50%;
  101. display: flex;
  102. flex-direction: column;
  103. align-items: center;
  104. .icon {
  105. width: 50%;
  106. height: 100%;
  107. padding: 10rpx;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. // padding: 10rpx;
  112. margin-bottom: 5rpx;
  113. border: 2rpx solid #999;
  114. }
  115. }
  116. }
  117. }
  118. }
  119. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/152926?site
推荐阅读
相关标签
  

闽ICP备14008679号