I'm trying to use Lottie files in my project; I have tried many way but none of them work... nothing appears.
I tried two ways:
lottieAnimation()
setupAnimation()
I also tried through UIView.
import UIKit
import Lottie
class BonusVC: UIViewController {
@IBOutlet weak var containerAnim: UIView!
var animation : AnimationView?
let animationView = AnimationView()
override func viewDidLoad() {
super.viewDidLoad()
lottieAnimation()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
lottieAnimation()
//setupAnimation()
}
func setupAnimation() {
animation = AnimationView(name: "wallet")
animation?.frame = self.containerAnim.frame
self.containerAnim.addSubview(animation!)
animation?.loopMode = .autoReverse
animation?.contentMode = .scaleAspectFit
animation?.play()
}
func lottieAnimation() {
let animation = Animation.named("wifi", subdirectory: "LottieAnimation")
animationView.animation = animation
animationView.contentMode = .scaleAspectFit
view.addSubview(animationView)
animationView.backgroundBehavior = .pauseAndRestore
animationView.translatesAutoresizingMaskIntoConstraints = false
animationView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true
animationView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
animationView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -12).isActive = true
animationView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
animationView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .horizontal)
animationView.play()
}
}