我成功地使用了 panResponder 并移动了图像内的元素,但它没有根据鼠标移动,它太快并且不会停留在图像边框中。
**状态 x 和状态 y 是数组的长度。我添加了一个按钮,每次单击它都会打开另一个 inputText 并将其推送到数组
DragTextView.js:
this.panResponder = PanResponder.create({
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) => {
// then start dragging
},
onPanResponderMove: (evt, gestureState) => {
// then dragging
console.log("evt = ", evt.target);
console.log("gestureState = ", gestureState);
this.setState({
x: this.state.x + gestureState.dy,
y: this.state.y + gestureState.dx,
});
},
onPanResponderTerminationRequest: (evt, gestureState) => true,
onPanResponderRelease: (evt, gestureState) => {
// then finish dragging
},
onPanResponderTerminate: (evt, gestureState) => {
},
onShouldBlockNativeResponder: (evt, gestureState) => {
return true;
},
});