title: How can I play my lottie animation with an OnTapGesture event?
body: <p>I followed MengTo's example of how to get a Lottie animation to play within SwiftUI. (<a href="https://www.youtube.com/watch?v=fVehE3Jf7K0" rel="nofollow noreferrer">https://www.youtube.com/watch?v=fVehE3Jf7K0</a>) However, I was wondering if anyone could help me understand how to initially present the first frame of the animation, but only have the animation play once a user taps on it in a button format.</p>
  <p>My current LottieButton file is as follows:</p>
  <pre><code>import SwiftUI
  import Lottie
  
  struct LottieButton: UIViewRepresentable {
  /// Create a button.
  let animationButton = AnimatedButton()
  var filename = &quot;LottieLogo2&quot;
  
  func makeUIView(context: UIViewRepresentableContext&lt;LottieButton&gt;) -&gt; UIView {
      let view = UIView()
      
      let animation = Animation.named(filename)
      animationButton.animation = animation
      animationButton.contentMode = .scaleAspectFit
      
      animationButton.translatesAutoresizingMaskIntoConstraints = false
      view.addSubview(animationButton)
      
      animationButton.clipsToBounds = false
         /// Set animation play ranges for touch states
      animationButton.setPlayRange(fromMarker: &quot;touchDownStart&quot;, toMarker: &quot;touchDownEnd&quot;, event: .touchUpInside)
         animationButton.setPlayRange(fromMarker: &quot;touchDownEnd&quot;, toMarker: &quot;touchUpCancel&quot;, event: .touchUpOutside)
         animationButton.setPlayRange(fromMarker: &quot;touchDownEnd&quot;, toMarker: &quot;touchUpEnd&quot;, event: .touchUpInside)
       
      NSLayoutConstraint.activate([
          animationButton.heightAnchor.constraint(equalTo: view.heightAnchor),
          animationButton.widthAnchor.constraint(equalTo: view.widthAnchor),
      ])
      
      return view
      
  }
  
  func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext&lt;LottieButton&gt;) {
      
      }
  }
  </code></pre>
  <p>And then I just have a simple view that is displaying the animation:</p>
  <pre><code>struct InboxView: View {
  var body: some View {
      VStack {
          Button(action: {}) {
          LottieButton(filename: &quot;inbox-notification&quot;)
          .frame(width: 100)
              }   
          }
      }
  }
  </code></pre>