首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >animated.loop防止animated.sequence中的animated.timing

animated.loop防止animated.sequence中的animated.timing
EN

Stack Overflow用户
提问于 2019-12-31 08:39:12
回答 2查看 99关注 0票数 1

我想运行一个动画,在这个动画中,棒球棒在球开始旋转并在屏幕上移动后,首先击打一个球,我有一个问题,当我在animated.sequence中编写一个animated.loop (用于旋转球)时,所有在animated.loop之后编写的animated.timing代码都被阻止了我该如何解决这个问题?

代码语言:javascript
复制
const ColorBox =()=>{

   const BaseballValue=new Animated.Value(0);
   const BaseballValue2=new Animated.Value(0);
   const BaseballValue3=new Animated.Value(0);
   const BallValue= new Animated.Value(0);
   const BallValue2= new Animated.Value(0);
useEffect(()=>{

  Animated.sequence([

    Animated.timing(BaseballValue,{
toValue:1,
duration:500,
easing:Easing.ease


    }),
     Animated.timing(BaseballValue3,{
     toValue:1,
     duration:400,
     easing:Easing.ease


     }),


    Animated.timing(BaseballValue2,{

    toValue:1,
    duration:400,
    easing:Easing.ease



    }),
   Animated.loop(
    Animated.timing(BallValue,{
    toValue:1,
    duration:800,
    easing:Easing.linear,
    delay:0



    })),

 Animated.spring(BallValue2,{

toValue:1,




 })





  ]).start();


})




const SpinBaseball=BaseballValue.interpolate({
inputRange:[0,1],
outputRange:['0deg','-90deg']


})


const BackwardBaseball=BaseballValue3.interpolate({
   inputRange:[0,1],
   outputRange:[0,-30]


})



const MovingBaseball=BaseballValue2.interpolate({
inputRange:[0,1],
outputRange:[0,210]


})


const SpinBall=BallValue.interpolate({
inputRange:[0,1],
outputRange:['0deg','360deg']

})


const MovingverticalBall=BallValue2.interpolate({

inputRange:[0,1],
outputRange:[0,150]


})







 return(

    <View>
<View style={{flex:1, justifyContent:'center', alignItems:'center'}}>
   <Animated.Image
    source={require('.././images/ball.png')}

    style={{...styles.ball, transform:[{rotate:SpinBall}, {translateX:MovingverticalBall}] }}

   >
   </Animated.Image>
   </View>
 <View style={{flex:1, justifyContent:'center', alignItems:'center'}}>

  <Animated.Image
   source={require('.././images/baseball.png')}
   style={{...styles.baseball, transform:[{rotate:SpinBaseball},{translateX:BackwardBaseball}, {translateX:MovingBaseball}]}}
  >



  </Animated.Image>

 </View>

 </View>
 )


}

export default ColorBox;



const styles=StyleSheet.create({

   ball:{
   width:80,
   height:80

   },

baseball:{
   width:250,
   height:100,




}




})
EN

回答 2

Stack Overflow用户

发布于 2019-12-31 17:51:57

并行运行一个函数,在里面你将同时运行序列和循环

代码语言:javascript
复制
 Animated.parallel([
      Animated.sequence([
        Animated.timing(BaseballValue, {
          toValue: 1,
          duration: 500,
          easing: Easing.ease,
        }),
        Animated.timing(BaseballValue3, {
          toValue: 1,
          duration: 400,
          easing: Easing.ease,
        }),
        Animated.timing(BaseballValue2, {
          toValue: 1,
          duration: 400,
          easing: Easing.ease,
        }),
        Animated.spring(BallValue2, {
          toValue: 1,
        }),
      ]),

      Animated.loop(
        Animated.timing(BallValue, {
          toValue: 1,
          duration: 800,
          easing: Easing.linear,
          delay: 0,
        }),
      ),
    ]).start();
  });
票数 1
EN

Stack Overflow用户

发布于 2020-01-16 16:25:01

您可以使用Animated.parallel方法

并行调用将同时在数组触发器中具有所有已定义的动画。

有关更多详细信息,请参阅Animated.parallel

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59538366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档