Swift中具有Lottie动画的关闭函数

问题描述 投票:0回答:1

是否有办法知道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()。有没有办法做到这一点?找不到任何东西!

ios swift closures lottie
1个回答
1
投票

Lottie动画基本播放

AnimationView.play(完成:LottieCompletionBlock?)

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

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

示例:

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

您可以在https://airbnb.io/lottie/#/ios?id=enabling-and-disabling-animation-nodes中找到更多信息

© www.soinside.com 2019 - 2024. All rights reserved.