react-native – 使用PanResponder进行锁定运动
发布时间:2020-12-15 20:40:57 所属栏目:百科 来源:网络整理
导读:使用react native PanResponder,当屏幕触摸坐标超出某个值范围时,如何阻止移动? 例如,如何阻止用户将组件移动到屏幕上某个y位置以下? PanResponder使用Gesture Responder System. 我正在仔细阅读文档,但我找不到答案. 任何帮助是极大的赞赏. 查看您提供的P
使用react native
PanResponder,当屏幕触摸坐标超出某个值范围时,如何阻止移动?
例如,如何阻止用户将组件移动到屏幕上某个y位置以下? PanResponder使用Gesture Responder System. 我正在仔细阅读文档,但我找不到答案. 任何帮助是极大的赞赏.
查看您提供的PanResponder文档页面(
https://facebook.github.io/react-native/docs/panresponder.html),我认为您可以修改示例以满足您的需求.
负责响应手势采取操作的函数是PanResponder的一个属性,名为onPanResponderMove,在示例代码中看起来像这样: _handlePanResponderMove: function(e: Object,gestureState: Object) { this._circleStyles.style.left = this._previousLeft + gestureState.dx; this._circleStyles.style.top = this._previousTop + gestureState.dy; this._updateNativeStyles(); }, gestureState对象的位置如下所示: stateID - ID of the gestureState- persisted as long as there at least one touch on screen moveX - the latest screen coordinates of the recently-moved touch moveY - the latest screen coordinates of the recently-moved touch x0 - the screen coordinates of the responder grant y0 - the screen coordinates of the responder grant dx - accumulated distance of the gesture since the touch started dy - accumulated distance of the gesture since the touch started vx - current velocity of the gesture vy - current velocity of the gesture numberActiveTouches - Number of touches currently on screen 您可以在_handlePanResponderMove中添加条件检查以确定gestureState.y0是否低于某个阈值,并且只应用更改 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |