反应原生,动画负旋转



我正在使用平移响应器来捕获用户的滑动移动,向下或向上,然后旋转一个圆圈:

如果为阳性:

 Animated.decay(animation, {velocity: fingerVelocity}).start();

如果为负数:

 Animated.decay(animationNegative, {velocity: fingerVelocity}).start();

然后我用上面旋转两个不同的圆圈:

  const animationStyle = animation.interpolate({
        inputRange: [0, 300],
        outputRange: ["0deg", "360deg"],
        extrapolate: 'identity'
    });
  const animationNegativeStyle = animationNegative.interpolate({
        inputRange: [0, 300],
        outputRange: ["0deg", "-360deg"],
        extrapolate: 'identity'
    });

对于positive它工作正常,但对于负数,它逆时针旋转 350 度,然后顺时针旋转 .

注意:我使用identity的原因是因为动画类型是decay,我不知道当时的值可能是多少,decay动画的速度取决于用户滑动的速度。

因此,当我记录值时,负值是这样的:

value interpolatedValue 0 -360 1 -359 2 -358 3 -357 .... 360 0 361 1 362 2 ....

我知道问题是identity,但如何解决呢?

这甚至可以使用 Animated API 吗?

我很

确定这是解决方案。

你的正常衰变 :

Animated.decay(animation, {velocity: fingerVelocity}).start();

现在值正在增加,这不是您想要的,您希望它们减少

 const animationNegative = Animated.multiply(animationNegative, -1);
 const animationNegativeStyle = animationNegative.interpolate({
        inputRange: [0, 1],
        outputRange: ["0deg", "1deg"], // we don't care, we just want the identity to kick in and use the value as is
        extrapolate: 'identity'
    });
 const animationNegativeStyle = animationNegative.interpolate({
        inputRange: [0, 300],
        outputRange: ["360deg", "0deg"],
        extrapolate: 'identity'
    });

我不确定这个解决方案是否有效,但至少您可以尝试一下并分享它的结果

最新更新