我一直在研究PanResponder。我的目前的工作假设是,如果有两个正在向外移动的触摸点,我将在onPanResponderMove
函数中检测到它们,并增加元素的大小。
这似乎是一种比较混乱的方法。是否有更流畅的方式?
我一直在研究PanResponder。我的目前的工作假设是,如果有两个正在向外移动的触摸点,我将在onPanResponderMove
函数中检测到它们,并增加元素的大小。
这似乎是一种比较混乱的方法。是否有更流畅的方式?
minimumZoomScale
和maximumZoomScale
是仅适用于iOS的属性。 - Andrew注意:本答案与全局响应器无关,而是解答如何在React Native中实现捏合缩放的主要问题。
使用Expo或未使用Expo的React-Native,您可以从react-native-gesture-handler导入PinchGestureHandler
。这里还有其他手势处理程序:react-native-gesture-handler
import { PinchGestureHandler } from 'react-native-gesture-handler';
举个例子,假设我们正在使用相机,并且希望检测捏合手势进行缩放:
<PinchGestureHandler
onGestureEvent={this.onPinchGestureEvent}
>
<View>
<Camera
type={cameraType}
flashMode={flashMode}
zoom={zoom}
style={styles.preview}
ref={camera => this.camera = camera}
/>
</View>
</PinchGestureHandler>
onPinchGestureEvent = event => {
console.log(event.nativeEvent.scale);
}
evt
。
这是React-Native文档中所说的。evt is a synthetic touch event with the following form:
nativeEvent
changedTouches - Array of all touch events that have changed since the last event
identifier - The ID of the touch
locationX - The X position of the touch, relative to the element
locationY - The Y position of the touch, relative to the element
pageX - The X position of the touch, relative to the root element
pageY - The Y position of the touch, relative to the root element
target - The node id of the element receiving the touch event
timestamp - A time identifier for the touch, useful for velocity calculation
touches - Array of all current touches on the screen
https://github.com/msand/zoomable-svg/blob/master/index.js
支持子元素的视口变换和按下/拖动事件处理程序。