【问题标题】:How to add extra value to the Animated Value on Animated.Event?如何为 Animated.Event 上的动画值添加额外的值?
【发布时间】:2019-09-27 08:38:49
【问题描述】:

我正在尝试向当前事件值添加新事件值,而不是替换它们。

此代码将 touchXtouchY 值替换为 translationXtranslationX

    Animated.event(
      [
        {
          nativeEvent: {
            translationX: this.touchX,
            translationY: this.touchY
          }
        }
      ],
      {
        useNativeDriver: false
      }
    )(event);

我已经厌倦了运行这段代码来实现它

    this.touchX.setValue(
      Animated.add(this.touchX, new Animated.Value(translationX))
    );
    this.touchY.setValue(
      Animated.add(this.touchY, new Animated.Value(translationY))
    );

不幸的是,当尝试将touchX 应用于我的动画组件Transform with key of "translateX" must be a number: {"translateX":"[object Object]0"} 时,这会导致错误

我希望 touchX 在每个事件之后等于 this.touchX + translationX

【问题讨论】:

    标签: javascript react-native animation


    【解决方案1】:

    Animated.Add() 正在返回动画对象,setValue 在这种情况下需要一个数字。

        this.touchX.setValue(this.touchX._value + translationX);
        this.touchY.setValue(this.touchY._value + translationY);
    

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 1970-01-01
      • 2017-03-09
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多