如何停止本机动画 [英] How to stop react-native animation
本文介绍了如何停止本机动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在响应本机中停止动画,但是它不起作用。
我尝试使用 stopAnimation方法做到这一点
I am trying to stop animation in react native, but it does not work. I try to do this with stopAnimation method
这是我的代码:
constructor(props) {
super(props);
//...
this.state = {
posY: new Animated.Value(0),
posX: new Animated.Value(0),
//...
};
}
componentWillMount(){
//...
let eventEmitter = getGlobalEventEmitter();
eventEmitter.emit('initialize', {words : true});
eventEmitter.addListener('startGame', ()=>{
this.setState({initialized: true});
this.updateText();
});
}
updateText(){
let currentText = [];
//... set some values to currentText
this.props.setText(currentText); // store in redux
this.startText(this.effects[textEffect]['duration']);
}
startText(duration) {
let viewHeight = 530;
let fallTo = 500;
Animated.timing(
this.state.posY,
{
toValue: fallTo,
duration: duration
}
).start();
let stopAnimation = function(){
this.state.posY.stopAnimation();
console.log("ANIMATION SHOULD STOP");
};
stopAnimation = stopAnimation.bind(this);
eventEmitter.addListener('wordGuessed', ()=>{
stopAnimation();
});
}
在其他组件中,我射击 wordGuessed
事件,控制台日志将起作用。我在做什么错?
In the other component I am firing wordGuessed
event, and the console log works. What I am doing wrong?
推荐答案
只需打电话
Animated.timing(
this.state.posY
).stop();
这篇关于如何停止本机动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文