首页 > 解决方案 > 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
}

行动:

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

我想要实现的是能够self.deleteWishCallback?() 调用self.successAnimation.play(). 有没有办法做到这一点?在这方面找不到任何东西!

标签: iosswiftclosureslottie

解决方案


Lottie 动画基本玩法

AnimationView.play(completion: LottieCompletionBlock?)

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

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

例子:

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

你可以在这里找到更多


推荐阅读