【问题标题】:React Native , animated negative rotationReact Native,动画负旋转
【发布时间】:2018-04-16 12:28:40
【问题描述】:

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

如果是肯定的:

 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 吗?

【问题讨论】:

    标签: react-native react-animated


    【解决方案1】:

    我很确定这是解决方案。

    你的正常衰变:

    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'
        });
    

    【讨论】:

    • 哦该死,简单,我怎么没想到,该死
    【解决方案2】:
     const animationNegativeStyle = animationNegative.interpolate({
            inputRange: [0, 300],
            outputRange: ["360deg", "0deg"],
            extrapolate: 'identity'
        });
    

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

    【讨论】:

    • 谢谢,但我确定它不会起作用。你显然是从 360 度到正方向的 0 度。
    • 正确,但是当identity启动时,将使用实际值,并且由于衰减,实际值始终为正
    猜你喜欢
    • 2020-01-19
    • 2022-08-19
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多