title: How to stop a Lottie animation manually
body: <p>I use the Lottie animation library in XCode. But when I go to another page, the animation is running in the background. When I go back the main page, the animation is running twice and there is too much RAM being consumed. How can I fix this problem? and how can I stop the animation after a specific time?</p>
  <pre><code>import UIKit
  import Lottie
  
  class CoffeeSpecialFortunePageVC: UIViewController {
      
      @IBAction func PopUpIn(_ sender: Any) {
          animateIn(desiredView: PopupBlur)
          animateIn(desiredView: popupView)
          animation()
      }
      @IBAction func SuccesBtn(_ sender: UIView) {
          animateOut(desiredView: PopupBlur)
          animateOut(desiredView: popupView)         
      }
           
      @IBOutlet var popupView: AnimationView!
      @IBOutlet var PopupBlur: UIVisualEffectView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          
          view.backgroundColor = UIColor.purple
          PopupBlur.bounds = self.view.bounds
          popupView.bounds = CGRect(x: 0, y: 0, width: self.view.bounds.width * 0.9, height: self.view.bounds.height * 0.4)
          // Do any additional setup after loading the view.
      }
      func animation() {
          popupView! = .init(name: &quot;check1&quot;)
          popupView?.frame = view.bounds
          view.addSubview(popupView!)
          popupView?.play()
          popupView.contentMode = .scaleAspectFit
          popupView.frame.size.height = 350
          popupView.frame.size.width = 350
          popupView.center.x = view.center.x
          popupView.center.y = view.center.y 
  
               
      }
  
      func animateIn(desiredView: UIView) {
          let backgraundview = self.view!
          backgraundview.addSubview(desiredView)
          desiredView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
          desiredView.alpha = 0
          desiredView.center = backgraundview.center
          UIView.animate(withDuration: 0.3, animations:{
              desiredView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
              desiredView.alpha = 1
              
          })                       
      }
      func animateOut(desiredView: UIView) {
          UIView.animate(withDuration: 0.3, animations: {
              desiredView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
              desiredView.alpha = 0
          },completion: {_ in
              desiredView.removeFromSuperview()                
              
          })            
      }    
  }
  </code></pre>
  <p><img src="https://i.stack.imgur.com/LzaAp.png" alt="enter image description here" /></p>