2017-04-13 107 views
0

我想在屏幕上制作一系列动画,其中一秒会无限循环。我有一个问题,正确调用它们。我试图从componentDidmount中删除.start()并执行.start((()=> this.animate2),但它弄乱了整个动画。我无法弄清楚如何正确地做到这一点。动画的循环序列

在此先感谢!

为了简化它看起来像这样的代码:

animate1(){Animated.sequence([...])} 
animate2(){Animated.sequence([...])} 

在componentDidmount我叫他们两个:

componentDidMount() { 
     Animated.sequence([ 
     this.animate1(), 
     Animated.delay(3000), 
     this.animate2() 
     ]).start(); 

回答

0

你只想animate2循环下去吗?如果你试图分离这些动画呢?

componentDidMount() { 
    Animated.sequence([ 
    this.animate1(), 
    Animated.delay(3000), 
    ]).start(() => this.animate2()); 
} 

animate2 =() => { 
//not sure what this does but you would put that logic here 
//for example 
    Animated.timing(
    this.state.fadeAnim, 
    { 
    toValue: 1, 
    } 
).start(() => this.animate2()); // recursively call this.animate2 
} 
+0

我试过这样做,但问题是,然后animate2()几乎立即开始动画,不尊重componentDidMount()中的顺序。此外,在函数运行一次后,我得到一个错误:undefined不是一个对象(评估'动画[current] .start') – misi06

0

@Matt Aft 谢谢!您的回复实际上是双重检查后解决我的问题!非常感谢! 祝你有美好的一天:)