Lottie-ios: Listen to animation progress change

Created on 4 Dec 2017  路  1Comment  路  Source: airbnb/lottie-ios

This is more of a question than issue. Is there a way in lottie to get continuous animationProgress. I am aware that we can use UIKit addObserver but it doesn't seem to be working. Any other way?

Most helpful comment

@RishabhTayal You can use a CADisplayLink to get the animation's progress when the screen is updated.

- (void)animationObserver {
   CADisplayLink *displayLink =[CADisplayLink displayLinkWithTarget:self 
   selector:@selector(animationProgress)];
   [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

   [self.lottieAnimation playWithCompletion:^(BOOL animationFinished) {
      [displayLink invalidate];
   }];
}

- (void)animationProgress {
  NSLog(@"Progress %f", self.lottieAnimation.animationProgress);
}

>All comments

@RishabhTayal You can use a CADisplayLink to get the animation's progress when the screen is updated.

- (void)animationObserver {
   CADisplayLink *displayLink =[CADisplayLink displayLinkWithTarget:self 
   selector:@selector(animationProgress)];
   [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

   [self.lottieAnimation playWithCompletion:^(BOOL animationFinished) {
      [displayLink invalidate];
   }];
}

- (void)animationProgress {
  NSLog(@"Progress %f", self.lottieAnimation.animationProgress);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ushaka picture Ushaka  路  5Comments

amannayak0007 picture amannayak0007  路  3Comments

loganblevins picture loganblevins  路  3Comments

zhangjunmax picture zhangjunmax  路  3Comments

chrisballinger picture chrisballinger  路  4Comments