我有按钮A启动的顺序动画,如何通过按钮B停止动画?谢谢
答案 0 :(得分:1)
将动画存储在状态变量中,并在点击按钮时调用start
或stop
:
constructor() {
super(props);
var my_animation = ... // define your animation here
this.state = {
my_animation: my_animation;
}
}
startAnimation() {
this.state.my_animation.start();
}
stopAnimation() {
this.state.my_animation.stop();
}
render() {
<Button onPress={() => this.startAnimation()} />
<Button onPress={() => this.stopAnimation()} />
}
有关start
和stop
的更多信息,请参阅https://facebook.github.io/react-native/docs/animations.html