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
}
行动:
@objc func checkButtonTapped(){
self.deleteWishCallback?()
self.successAnimation.isHidden = false
self.successAnimation.play()
}
我想要实现的是能够self.deleteWishCallback?()
调用self.successAnimation.play()
. 有没有办法做到这一点?在这方面找不到任何东西!
解决方案
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
}
你可以在这里找到更多
推荐阅读
- amazon-web-services - 如何修复在本地服务器上正常运行但部署到 AWS 后无法运行的程序?
- javascript - 我应该为 Electron 应用程序中使用的授权调用使用什么重定向 URI?
- java - 我可以在java中的泛型函数中为泛型对象的特定属性设置值吗?
- python - 如何解决第二个脚本中的 EOF 问题(虚线下方)?
- javascript - 如何使用 appendChild 将多个元素添加到父元素?
- bash - 使用 Bash 成对列出文件
- ios - iOS 设备中 admob 广告的先决条件问题
- c# - 为什么 CS1501 错误消息 18+ 重载和 0 个参数?
- function - 运行函数时命令窗口中的名称错误
- c++ - 函数重载中可以有多少个参数?