0

我正在使用它在animated.view https://software-mansion.github.io/react-native-gesture-handler/docs/handler-pan.html上实现平移

此动画视图还使用相同的库启用了捏合和缩放

<Animated.View 
  style={[{width: this.props.width, height: this.props.height, backgroundColor:this.props.bgColor},
      {
       transform: [
         { scale: this._scale },
         { translateX: this._translateX },
         { translateY: this._translateY },
         ],
          },
       ]} collapsable={false}>
        {this.props.children}
 </Animated.View>

当视图处于其正常缩放/比例时,平移将按预期工作。视图随着手指移动。

如果您缩小(视图变小),平移手势移动的视图像素会随着手指的每个等效移动而减少。

如果放大(视图真的很大),平移手势会移动很多视图。因此,即使您手指的最细微移动也会显着移动视图,并且很难获得准确的平移。

有没有办法根据你有多少缩放/比例来调整平移灵敏度?我似乎在文档中找不到任何可以使它起作用的属性。有解决办法吗?

想要的最终结果:
缩小,提高平移速度/灵敏度
放大,降低平移速度/灵敏度

4

1 回答 1

1

您需要对比例值进行一些数学运算。

像这样的东西应该工作。

<Animated.View 
  style={[{width: this.props.width, height: this.props.height, backgroundColor:this.props.bgColor},
      {
       transform: [
         { scale: this._scale },
         { translateX: Animated.divide(this._translateX, this._scale) },
         { translateY: Animated.divide(this._translateY, this._scale) },
         ],
          },
       ]} collapsable={false}>
        {this.props.children}
 </Animated.View>

如果您允许多次捏合以保持缩放,或者允许多次平移以保持改变平移值,那么您还需要存储以前的比例并将其纳入平移计算。

于 2020-07-16T15:05:14.947 回答