简体   繁体   English

如何在本机反应中使用洛蒂速度到持续时间

[英]How to use lottie speed to duration in react native

I'm using this animation https://assets2.lottiefiles.com/packages/lf20_k5lht2yq.json .我正在使用这个 animation https://assets2.lottiefiles.com/packages/lf20_k5lht2yq.json

For some reason, the duration prop not working.出于某种原因,持续时间道具不起作用。

<LottieView
          autoPlay={true}
          duration={60000}
          loop={false}
          source={assets.LOTTIE_LEVEL_PROGRESS}
          style={styles.lottie}
        />

As you can see, I'm trying to play animation for a 60 seconds, but in real time it playing about 4 seconds.如您所见,我正在尝试播放 animation 60 秒,但实时播放约 4 秒。

The lottie library contain speed prop that receives a number from 0 to 1. lottie 库包含 speed 属性,它接收从 0 到 1 的数字。

Is there a way to play this anim for a 60 (dynamic number, may change to 120 seconds and more) seconds?有没有办法让这个动画播放 60 秒(动态数字,可能会变成 120 秒或更多)秒?

I think duration in this library means the ms that one animation takes in order to execute.我认为这个库中的持续时间是指一个 animation 执行所需的毫秒数。 So in your code, your animation execute only once and it takes 1 minutes.所以在你的代码中,你的 animation 只执行一次,需要 1 分钟。 In other words it is so slow that you cant even see the execution.换句话说,它太慢了,你甚至看不到执行。 for execute your animation in normal speed for about 1m you need the following code:要以正常速度执行 animation 约 1m,您需要以下代码:

function Example() {
  const [loop, setLoop] = useState(true);

  useEffect(
    () => {
      let timer = setTimeout(() => setLoop(false), 60000);
      return () => {
        clearTimeout(timer);
      };
    },[]);

  return (
    <LottieView
        autoPlay
        loop={loop}
        source={assets.LOTTIE_LEVEL_PROGRESS}
        style={styles.lottie}
     />
  );
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM