1***@qq.com
1***@qq.com
  • 发布:2024-02-02 13:52
  • 更新:2024-04-28 13:04
  • 阅读:72

pan-gesture-handler worklet:ongesture="handlePan"事件不触发

分类:HBuilderX

<pan-gesture-handler worklet:ongesture="handlePan" style="flex-shrink: 0;">
<view class="comment-header" @touchend="handleTouchEnd">
<view class="comment-handler"></view>
留言
</view>
</pan-gesture-handler>

handlePan(gestureEvent) {
'worklet'
console.log(2134231312312343234234234234);
// 滚动半屏的位置
if (gestureEvent.state === GestureState.ACTIVE) {
// deltaY < 0,往上滑动
this.upward.value = gestureEvent.deltaY < 0
// 当前半屏位置
const curPosition = this.transY.value
// 只能在 [statusBarHeight, screenHeight] 之间移动
const destination = clamp(curPosition + gestureEvent.deltaY, statusBarHeight, screenHeight)
if (curPosition === destination) return
// 改变 transY,来改变半屏的位置
this.transY.value = destination
}

            if (gestureEvent.state === GestureState.END || gestureEvent.state === GestureState.CANCELLED) {  
                if (this.transY.value <= screenHeight / 2) {  
                    // 在上面的位置  
                    if (this.upward.value) {  
                        this.scrollTo(statusBarHeight)  
                    } else {  
                        this.scrollTo(screenHeight / 2)  
                    }  
                } else if (this.transY.value > screenHeight / 2 && this.transY.value <= this.initTransY.value) {  
                    // 在中间位置的时候  
                    if (this.upward.value) {  
                        this.scrollTo(screenHeight / 2)  
                    } else {  
                        this.scrollTo(this.initTransY.value)  
                    }  
                } else {  
                    // 在最下面的位置  
                    this.scrollTo(this.initTransY.value)  
                }  
            }  
        },
2024-02-02 13:52 负责人:无 分享
已邀请:

要回复问题请先登录注册