Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何重置本地动画?_Reactjs_React Native - Fatal编程技术网

Reactjs 如何重置本地动画?

Reactjs 如何重置本地动画?,reactjs,react-native,Reactjs,React Native,我用来自的动画制作了一些简单的动画 动画在第一次按下后按预期工作,但我不知道如何重置它,以便在下一次点击时工作 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.interp

我用来自的
动画制作了一些简单的动画
动画在第一次按下后按预期工作,但我不知道如何重置它,以便在下一次点击时工作

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();
}
在渲染中

<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>
{this.handlePress();}}>

有什么建议吗?谢谢

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

您可以使用
Aminated.reset()
方法。

在最新的API中,我似乎再也找不到
setValue
。此方法是否已弃用?