我在 React Native 中使用 Gesture Handler 库中的捏和平移。到目前为止,它运行良好,但我一直在努力解决一个新问题。我想为比例设置一个最小值 1,以便用户不能将图像缩小到超过原始图像的比例 1。我希望能够放大到大于 1 的比例值,但我没有'不希望比例值小于 1,因此当用户尝试以比例小于 1 的方式缩小图像时,缩放应该停止。我该怎么做?
_onPinchHandlerStateChange = event => {
if (event.nativeEvent.oldState === State.ACTIVE) {
this._lastScale *= event.nativeEvent.scale;
this._baseScale.setValue(this._lastScale);
this._pinchScale.setValue(1);
}
而在 XML 中,Pinch 是这样的:
<PinchGestureHandler
onGestureEvent={this._onPinchGestureEvent}
ref={pinchRef}
enabled={this.state.drawModeButton !== drawModeButtons.LASSO &&
this.state.drawModeButton !== drawModeButtons.RECTANGLE &&
this.state.drawModeButton !== drawModeButtons.BRUSH }
simultaneousHandlers={panRef}
onHandlerStateChange={this._onPinchHandlerStateChange}>