imengyu
imengyu
  • 发布:2022-02-21 10:59
  • 更新:2022-02-21 11:09
  • 阅读:956

nvue ios picker-view 歪歪扭扭,选择出现偏移!

分类:nvue

如下,这是一个简单的pickview组件:

我通过样式设置了高度,这个组件在vue和android上是正常的,选择不会出现偏移。

但是在IOS NVUE上,选择器文字歪歪扭扭,没法局中。

还有更严重的问题,选择器总是有莫名其妙的偏移,这导致,数据越多,越往下滑动,偏移的越多,导致滑动到最后一格,返回的value直接超出了,选择不了数据。

如下,我滑动到最后一格应该是12月,index应该是11,但是index直接是14,为什么?
console.log输出:[21,14,0],但是我这里月份数据只有12条,最大应该是11,为什么偏了这么多?


<template>  
  <picker-view  
        :value="value"  
        :style="pickerStyle"  
        :indicatorStyle="indicatorStyle"  
        @change="onChange"   
>  
        <picker-view-column>  
            <view class="item" v-for="(item,index) in years" :key="index">  
                <text class="text">{{item}}年</text>  
            </view>  
        </picker-view-column>  
        <picker-view-column>  
            <view class="item" v-for="(item,index) in months" :key="index">  
                <text class="text">{{item}}月</text>  
            </view>  
        </picker-view-column>  
        <picker-view-column>  
            <view class="item" v-for="(item,index) in days" :key="index">  
                <text class="text">{{item}}日</text>  
            </view>  
        </picker-view-column>  
    </picker-view>  
</template>  
<script>  
    export default {  
        props: {  
            pickerStyle: {  
                type: String,  
                default: 'width:730rpx; height:300rpx;'  
            },  
            indicatorStyle: {  
                type: String,  
                default: 'height: 100rpx;'  
            },  
        },  
        data() {  
            return {  
                years: [ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,2011, 2012, 2013, 2014, 2015, 2016 ],  
                months: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ],  
                days: [ /* 数据太多省略 */ ],   
                value: [ 0, 0, 0 ],  
            }  
        },  
        methods: {  
            onChange(e) {  
                console.log(e.detail.value);  
            },  
        }  
    }  
</script>  

<style lang="scss" scoped>  
.item {  
    height: 100rpx;  
    display: flex;  
    flex-direction: column;  
    justify-content: center;  
    align-items: center;  
    text-align: center;  

    .text {  
        display: flex;  
        flex-direction: column;  
        justify-content: center;  
        align-items: center;  
        text-align: center;  
        font-size: 35rpx;  
    }  
}  
</style>

请问,要如何解决这个问题呢?

(不知道picker-view内部是怎么计算高度的,反正肯定有问题。感觉写这个picker-view的人的数学是不是美术老师教的,高度怎么算的,歪歪扭扭的很有美感是吧?)

2022-02-21 10:59 负责人:DCloud_iOS_XHY 分享
已邀请:
imengyu

imengyu (作者)

还有,偶尔有闪退的问题

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 nan; 79 165]. Layer: <CALayer:0x283226c40; position = CGPoint (39.5 82.5); bounds = CGRect (0 0; 79 165); delegate = <DCScrollerComponentView: 0x1589d5600; baseClass = UIScrollView; frame = (0 0; 79 165); clipsToBounds = YES; autoresizesSubviews = NO; gestureRecognizers = <NSArray: 0x283c04ba0>; layer = <CALayer: 0x283226c40>; contentOffset: {0, 0}; contentSize: {0, 748}; adjustedContentInset: {0, 0, 0, 0}>; contents = <CABackingStore 0x157fdaf70>; sublayers = (<WXLayer: 0x283226de0>); masksToBounds = YES; allowsGroupOpacity = YES; backgroundColor = <CGColor 0x2811d8c80> [<CGColorSpace 0x2816f3180> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; 普通灰度系数2.2描述文件; extended range)] ( 0 0 ); borderColor = <CGColor 0x2811dfb60> [<CGColorSpace 0x2816f3180> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; 普通灰度系数2.2描述文件; extended range)] ( 0 1 )>'  
*** First throw call stack:  
(0x1848d4928 0x198673480 0x1847d6288 0x187afa914 0x187ae87e4 0x187660b88 0x1875ee6d4 0x1875ef9e8 0x1875e9f10 0x1866d9604 0x1879a5200 0x187a7ce7c 0x184830bf4 0x1848547e8 0x184853bec 0x18484dd60 0x18484ced0 0x19af98570 0x18717a2d0 0x18717f84c 0x100ace7e4 0x18452b140)  
libc++abi: terminating with uncaught exception of type NSException  
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 nan; 79 165]. Layer: <CALayer:0x283226c40; position = CGPoint (39.5 82.5); bounds = CGRect (0 0; 79 165); delegate = <DCScrollerComponentView: 0x1589d5600; baseClass = UIScrollView; frame = (0 0; 79 165); clipsToBounds = YES; autoresizesSubviews = NO; gestureRecognizers = <NSArray: 0x283c04ba0>; layer = <CALayer: 0x283226c40>; contentOffset: {0, 0}; contentSize: {0, 748}; adjustedContentInset: {0, 0, 0, 0}>; contents = <CABackingStore 0x157fdaf70>; sublayers = (<WXLayer: 0x283226de0>); masksToBounds = YES; allowsGroupOpacity = YES; backgroundColor = <CGColor 0x2811d8c80> [<CGColorSpace 0x2816f3180> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; 普通灰度系数2.2描述文件; extended range)] ( 0 0 ); borderColor = <CGColor 0x2811dfb60> [<CGColorSpace 0x2816f3180> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; 普通灰度系数2.2描述文件; extended range)] ( 0 1 )>'  
terminating with uncaught exception of type NSException  
  • DCloud_iOS_XHY

    picker 的问题后续会优化,崩溃的问题从当前日志看出来具体什么原因,能否提供复现问题的环境?

    2022-02-23 20:15

  • imengyu (作者)

    回复 DCloud_iOS_XHY: 非常感谢。出现问题的环境是 iPhone8 Plus,iOS 14.8.1 代码是上面的这段代码,大概是一个日期选择器,没有其他内容,上面省略了日的数据。

    我们发现,如果页面一进来就加载picker-view和数据,那么picker-view就是乱的,如果加个延时, 延时大概 300ms,再控制 v-if 把picker-view显示,picker-view就是正常的,具体不知道是什么原因。

    这个闪退是picker-view混乱的时候上下滑动的时候出现的,具体不知道是什么原因,很抱歉暂时弄不出来一个案例项目,代码比较多,可能是我们自己写的代码也有问题,后面改了一下几乎没有崩溃了。想了下可能是之前picker-view混乱的时候,选择出来的索引有问题,超出了,然后我们的代码里面有重新设置value回去的地方,就把错误的value设置回picker-view,value里面有 undefined,可能导致内部发生了错误。

    2022-02-24 10:23

  • DCloud_iOS_XHY

    好的好的,picker-view 数据多了混乱的问题后续会优化,有其他用户遇到这个问题我会让他们先按照你说的方式试试看,感谢反馈

    2022-02-24 15:09

  • 8***@qq.com

    回复 DCloud_iOS_XHY: 苹果15pro还会出现picker-view位置偏移问题

    2023-10-17 15:45

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