Swift 中 Lottie 动画的闭包函数

Chr*_*ris 0 closures ios swift lottie

有没有办法知道什么时候Lottie animation完成?我需要delete 一个tableViewCell 但只有在animation 完成之后。这是animation

设置:

    //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
}
Run Code Online (Sandbox Code Playgroud)

行动:

@objc func checkButtonTapped(){
    self.deleteWishCallback?()
    self.successAnimation.isHidden = false
    self.successAnimation.play()
}
Run Code Online (Sandbox Code Playgroud)

我想要实现的是能够self.deleteWishCallback?()self.successAnimation.play(). 有没有办法做到这一点?找不到任何关于此的信息!

Yas*_*eed 8

Lottie 动画基本播放

AnimationView.play(completion: LottieCompletionBlock?)
Run Code Online (Sandbox Code Playgroud)

从当前状态播放动画到其时间线的结尾。当动画停止时调用完成块。

参数: : completion:动画完成时调用的完成块。如果动画完成,则块将传递true,如果动画被中断,则传递false。可选的。

例子:

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

你可以在这里找到更多