Lottie animationView completion block not getting executed

Viewed 297
animationView!.play(fromProgress: AnimationProgressTime(y),
    toProgress: AnimationProgressTime(y),
       loopMode: LottieLoopMode.playOnce,
       completion: { (finished) in
        if finished {
          print("Animation Complete")

        } else {
          print("Animation cancelled")
        }
        let renderer = UIGraphicsImageRenderer(size: animationView!.bounds.size)
        let image = renderer.image { ctx in

            animationView!.drawHierarchy(in: animationView!.bounds, afterScreenUpdates: true)

        }
        completionBlock(image)
})

I'm working on an image processing application. I'm trying to add text animations to the app by using Lottie.

My problem is that the play completion block does not always execute. In the example I posted it doesn't execute, but if I move the part starting with let renderer = UIGraphicsImageRenderer(size: animationView!.bounds.size) and ending with completionBlock(image) out of the completion block, the play completion block runs.

My other issue is that even if play executes, I don't know how to wait for that to finish and only then return from my function.

0 Answers
Related