大叔刘
大叔刘
  • 发布:2021-02-27 03:20
  • 更新:2021-03-29 20:04
  • 阅读:935

【报Bug】iPhonex以上 屏幕安全区像素差了3-5个px 或 全面屏手机 均存在这种问题

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 10.15.8

HBuilderX类型: 正式

HBuilderX版本号: 3.1.2

手机系统: 全部

手机厂商: 苹果

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

测试过的手机:

无错误型号 redmi5A iPhone8 iPhonese 有错误型号 iPhonemini iPhone11 iPhone12 iPhone12 pro

示例代码:
<template>  
    <view class="content">  
        <scroll-view :scroll-x="true" style="white-space: nowrap;margin-left: 20rpx;  width: 730rpx; height: 100rpx ; background-color: #0077AA; padding-top: 200rpx;"  
         :show-scrollbar="true" :scroll-into-view="scrollintoview" :scroll-with-animation="true" id="tabtop">  
            <view style="width: 145rpx; display: inline-block;" v-for="(item,index) in tabBars" :key="item.id" :id="'tab'+index"  
             :class="tabIndex === index ? 'selectText l-color-main' : '' " @click="changeTab(index)">{{item.title}}</view>  
        </scroll-view>  

        <swiper style="background-color: #007AFF;   width: 750rpx; height: 490px;" @change="onChangeTab" :current="current">  
            <swiper-item v-for="(item,index) in tabBars" :key="item.id" >  
                <text>1</text>  
            </swiper-item>  

        </swiper>  
        <!-- <block v-for="item,index in list" :key="index">  
            <commenList :item="item" :index="index" @followed="followed" @doSupport="doSupport"></commenList>  
            <commonHorizontalLine></commonHorizontalLine>  
        </block> -->  

    </view>  
</template>  

<script>  
    import commenList from "@/component/common/common_list/common_list.vue"  
    import commonHorizontalLine from "@/component/common/common_horizontal_line/common_horizontal_line.vue"  
    export default {  
        components: {  
            commenList,  
            commonHorizontalLine  
        },  
        data() {  
            return {  
                tabIndex: 0,  
                current: 0,  
                scrollintoview: '',  
                tabBars: [{  
                    id: 0,  
                    title: "栏目0"  
                }, {  
                    id: 1,  
                    title: "栏目1"  
                }, {  
                    id: 2,  
                    title: "栏目2"  
                }, {  
                    id: 3,  
                    title: "栏目3"  
                }, {  
                    id: 4,  
                    title: "栏目4"  
                }, {  
                    id: 5,  
                    title: "栏目5"  
                }, {  
                    id: 6,  
                    title: "栏目6"  
                }, {  
                    id: 7,  
                    title: "栏目7"  
                }, {  
                    id: 8,  
                    title: "栏目8"  
                }, {  
                    id: 9,  
                    title: "栏目9"  
                }, {  
                    id: 10,  
                    title: "栏目10"  
                }],  
                list: [{  
                        cname: "昵称1",  
                        avatar: "/static/logo.png",  
                        post_time: "2021年02月26日13:02:01",  
                        is_follow: false,  
                        title: "文章的标题",  
                        title_pic: "/static/6acec660-4f31-11eb-a16f-5b3e54966275.jpg",  
                        support: {  
                            type: "support",  
                            support_count: 1,  
                            unsupport_count: 2  
                        },  
                        comment_count: 2,  
                        share_count: 2  
                    },  
                    {  
                        cname: "昵称2",  
                        avatar: "/static/logo.png",  
                        post_time: "2021年02月26日13:02:01",  
                        is_follow: false,  
                        title: "文章的标题",  
                        title_pic: "/static/6acec660-4f31-11eb-a16f-5b3e54966275.jpg",  
                        support: {  
                            type: "unsupport",  
                            support_count: 1,  
                            unsupport_count: 2  
                        },  
                        comment_count: 2,  
                        share_count: 2  
                    },  
                    {  
                        cname: "昵称3",  
                        avatar: "/static/logo.png",  
                        post_time: "2021年02月26日13:02:01",  
                        is_follow: false,  
                        title: "文章的标题",  
                        title_pic: null,  
                        support: {  
                            type: null,  
                            support_count: null,  
                            unsupport_count: 0  
                        },  
                        comment_count: null,  
                        share_count: null  
                    },  
                    {  
                        cname: "昵称3",  
                        avatar: "/static/logo.png",  
                        post_time: "2021年02月26日13:02:01",  
                        is_follow: false,  
                        title: "文章的标题",  
                        title_pic: null,  
                        support: {  
                            type: "unsupport",  
                            support_count: null,  
                            unsupport_count: 0  
                        },  
                        comment_count: null,  
                        share_count: null  
                    }  
                ]  
            }  
        },  
        onLoad() {  

        },  
        methods: {  
            changeTab(index) {  
                this.tabIndex = index,  
                    this.scrollintoview = 'tab' + index  
                this.current = index  
            },  
            onChangeTab(e) {  
                this.tabIndex = e.detail.current  
                this.scrollintoview = 'tab' + e.detail.current  
            },  
            // 关注功能  
            followed(index) {  
                this.list[index].is_follow = true  
                uni.showToast({  
                    title: "关注成功"  
                })  
            },  
            // 顶踩操作  
            doSupport(data) {  

                if (data.type == 'unsupport' && this.list[data.index].support.type != 'unsupport') {  
                    this.list[data.index].support.unsupport_count = this.list[data.index].support.unsupport_count + 1  
                    this.list[data.index].support.support_count = this.list[data.index].support.support_count - 1  
                    if (this.list[data.index].support.support_count < 0) {  
                        this.list[data.index].support.support_count = 0  
                    }  
                    uni.showToast({  
                        title: "踩了一下"  
                    })  
                }  

                if (data.type == 'support' && this.list[data.index].support.type != 'support') {  
                    this.list[data.index].support.unsupport_count = this.list[data.index].support.unsupport_count - 1  
                    this.list[data.index].support.support_count = this.list[data.index].support.support_count + 1  
                    if (this.list[data.index].support.unsupport_count < 0) {  
                        this.list[data.index].support.unsupport_count = 0  
                    }  
                    uni.showToast({  
                        title: "顶了一下"  
                    })  
                }  

                this.list[data.index].support.type = data.type;  
            }  
        },  

        onLoad() {  

        },  

        onReady() {  

            uni.getSystemInfo({  
                success: function(res) {  
                    console.log(res.windowHeight);  
                }  
            });  

            const query = uni.createSelectorQuery().in(this);  
            query.select('#tabtop').boundingClientRect(data => {  
              console.log("得到布局位置信息" + JSON.stringify(data));  
              console.log("节点离页面顶部的距离为" + data.top);  
            }).exec();  
        }  

    }  
</script>  

<style>  
    .content {  
        display: flex;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
    }  

    /* 禁止IOS 横向划动出现滚动条 */  
    /deep/.uni-scroll-view::-webkit-scrollbar {  
        display: none;  
    }  

    .selectText {  
        font-weight: bold;  
        font-size: 42rpx;  
    }  
</style>  

操作步骤:

1.获取屏幕的安全高度

    uni.getSystemInfo({  
                success: function(res) {  
                    console.log(res.windowHeight);  
                }  
            });  
});

2.获取第一个元素scroll-view的bottom
scroll-view元素的代码

<scroll-view :scroll-x="true" style="white-space: nowrap;margin-left: 20rpx;  width: 730rpx; height: 100rpx ; background-color: #0077AA; padding-top: 200rpx;"  
         :show-scrollbar="true" :scroll-into-view="scrollintoview" :scroll-with-animation="true" id="tabtop">  
            <view style="width: 145rpx; display: inline-block;" v-for="(item,index) in tabBars" :key="item.id" :id="'tab'+index"  
             :class="tabIndex === index ? 'selectText l-color-main' : '' " @click="changeTab(index)">{{item.title}}</view>  
        </scroll-view>  

3.获取scroll-view距离顶部的距离

    const query = uni.createSelectorQuery().in(this);  
            query.select('#tabtop').boundingClientRect(data => {  
              console.log("得到布局位置信息" + JSON.stringify(data));  
              console.log("节点离页面顶部的距离为" + data.top);  
            }).exec();

4.通过console.log的输出 手工进行计算

        <swiper style="background-color: #007AFF;   width: 750rpx; height: 490px;" @change="onChangeTab" :current="current">  
            <swiper-item v-for="(item,index) in tabBars" :key="item.id" >  
                <text>1</text>  
            </swiper-item>  

        </swiper>

5.可以发现 是可以上下滚动 5个像素 其他的如 iPhone12 和 pro 是3个像素 下面2张图片 可以通过放到 PS等工具查看 差了5个像素 图在附件

预期结果:

应该不能上下滚动

实际结果:

可以上下滚动

bug描述:

如:页面除 原生导航栏和原生底部导航 一共2个元素 第一个scroll-view 第二个 swiper 其中swiper高度为自动获取,如下

在媒体查询中获取到可使用窗口高度【windowHeight】A 后 ,再通过createSelectorQuery获取第一个元素的bottom B

那么A-B = C 应该是屏幕剩下的像素 ,而在测试后 把C给swiper后,发现可以上下滚动几个像素,并且出现了滚动条

安卓手机没发现问题【自己用的不是全面屏】,而发现有问题的手机都是iPhone系列X后的,也就是全面屏,不确定安卓的全面屏手机是否也存在这样的问题,在小屏幕的iPhone上发现没问题

联系:17310646585 Q857523518 可以远程提供演示

2021-02-27 03:20 负责人:无 分享
已邀请:
大叔刘

大叔刘 (作者)

来人啊

突然好想你

突然好想你

顶一下

  • 大叔刘 (作者)

    我以为官方来回复我了呢

    2021-03-01 15:28

  • DCloud_UNI_GSQ

    回复 大叔刘: 来了,测试确实有问题

    2021-03-01 17:02

  • 突然好想你

    回复 大叔刘: 有其他人顶,官方看到的几率更大,自己顶看到的几率更小

    2021-03-03 17:23

DCloud_UNI_GSQ

DCloud_UNI_GSQ

问题确认,已加分,后续修复

临时解决办法:

  1. 使用 css 来布局,不依赖 js 计算。
  2. 判断 ios 机型和系统版本自行修正高度(需要考虑后续修复的影响)
  • DCMarvel

    Nvue页面(不能使用%比)如何用css设置scroll-view 或swiper的高度?

    2021-03-02 15:30

  • DCloud_UNI_GSQ

    回复 DCMarvel: 用 flex 布局

    2021-03-02 15:38

DCloud_iOS_XHY

DCloud_iOS_XHY

此问题已在 HX 3.1.6 + 版本修复

该问题目前已经被锁定, 无法添加新回复