gpt4 book ai didi

reactjs - react native 中的动画可以暂停和重启吗?

转载 作者:行者123 更新时间:2023-12-01 22:23:04 27 4
gpt4 key购买 nike

onAnimation(){

var animation = Animated.timing(this.state.spin,{
toValue:1,
duration:4000,
easing:Easing.linear
});
animation.start();
}


onPause(){
this.state.spin.stopAnimation();
}

我正在练习 React Native 中的动画。如上代码所示,动画的速度会变慢,因为'the.state.spin'已经改变但动画时间仍然是4000ms。所以我想重置状态。但是'the.state.spin'是一个Animated。值(value)。我不知道如何在不减慢动画速度的情况下重新启动动画。

任何人都可以帮助我或告诉我暂停和重新启动动画的正确方法吗?

最佳答案

根据 Official Doc这里

您可以将回调传递给stopAnimation,例如:

this.state.spin.stopAnimation(this.callback);

然后在回调中停止动画后就可以得到最终值了。你可以对这个值做任何你想做的事情,比如调整duration来实现restart功能。

关于reactjs - react native 中的动画可以暂停和重启吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38813491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com