如何重设本机动画?

Cri*_* Tr 4 reactjs react-native

我已经使用做了一些简单的动画,Animated反应本土 第一onPress后如预期的动画作品,但我无法弄清楚如何重置,以使其成为下一个水龙头工作。

constructor(props) {
    super(props);
    this.spinValue = new Animated.Value(0);
    // Second interpolate beginning and end values (in this case 0 and 1)
    this.spin = this.spinValue.interpolate({
        inputRange: [0, 1, 2, 3, 4],
        outputRange: ['0deg', '4deg', '0deg', '-4deg', '0deg']
    });
}

handlePress() {
    // First set up animation 
    Animated.timing(
        this.spinValue,
        {
            toValue: 4,
            duration: 300,
        }
    ).start();
}
Run Code Online (Sandbox Code Playgroud)

并在渲染

<TouchableWithoutFeedback onPress={() => { this.handlePress(); }} >
                    <Animated.Image
                        source={someImg}
                        style={{ height: undefined, width: undefined, flex: 1, transform: [{ rotate: this.spin }, { perspective: 1000 }] }}
                        resizeMode={'contain'}
                        resizeMethod="resize"
                    />
</TouchableWithoutFeedback>
Run Code Online (Sandbox Code Playgroud)

有什么建议么?谢谢

Ant*_*amp 24

您可以this.spinValue.setValue(0)用来重置它。您可以将其添加到的开头handlePress

  • 我似乎在最新的 API 中找不到 `setValue` 了。此方法已被弃用吗? (2认同)