0

Is there a way to know when an Lottie animation is finished? I need to delete a tableViewCell but only AFTER the animation is finished. This is the animation:

Setup:

    //MARK: setup Loading-Animation
func setupLoadingAnimation(){

    successAnimation.translatesAutoresizingMaskIntoConstraints = false
    self.contentView.addSubview(successAnimation)

    successAnimation.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: -30).isActive = true
    successAnimation.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
    successAnimation.widthAnchor.constraint(equalToConstant: 160).isActive = true
    successAnimation.heightAnchor.constraint(equalToConstant: 160).isActive = true

    successAnimation.isHidden = true
    successAnimation.loopMode = .playOnce
}

Action:

@objc func checkButtonTapped(){
    self.deleteWishCallback?()
    self.successAnimation.isHidden = false
    self.successAnimation.play()
}

What I would like to achieve is to be able to call self.deleteWishCallback?() in the closure of self.successAnimation.play(). Is there a way to get this done ? Couldnt find anything on this!

Chris
  • 1,828
  • 6
  • 40
  • 108

1 Answers1

9

Lottie Animation Basic Playing

AnimationView.play(completion: LottieCompletionBlock?)

Plays the animation from its current state to the end of its timeline. Calls the completion block when the animation is stopped.

Parameters: : completion: A completion block that is called when the animation completes. The block will be passed true if the animation completes and false if the animation was interrupted. Optional.

Example:

starAnimationView.play { (finished) in
      // Animation finished
      //here if finised is true you can perform the action of deleting the tableviewCell
    }

You can find more HERE

Wahdat Jan
  • 3,988
  • 3
  • 21
  • 46
Yaseen Majeed
  • 350
  • 2
  • 11