首页 > 解决方案 > 动画被执行,但随后立即返回初始状态

问题描述

这是我的代码,我正在调用状态更改。它被执行,但随后立即返回其初始状态。我想让它保持它的位置,直到我告诉它。

  const spinValue = new Animated.Value(0)
  const widthValueX = new Animated.Value(0)

  const open = () => {
    Animated.spring(widthValueX, {toValue: 2, useNativeDriver: true}).start()
    Animated.spring(spinValue, {toValue: 2, useNativeDriver: true}).start()
  }

  const growX = widthValueX.interpolate({
    inputRange: [0, 1, 2],
    outputRange: [1, 1.5, 1]
  })

  const spinX = spinValue.interpolate({
    inputRange: [0, 1, 2],
    outputRange: ['0deg', '45deg', '90deg']
  })

标签: javascriptreactjsreact-nativeanimation

解决方案


推荐阅读