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/