title: Animating a SwiftUI view with UIView.animate
body: <p>I've noticed that <code>UIView.animate</code> is less quirky and 'smoother' with less lag than using <code>withAnimation { }</code> and the general Animation class in SwiftUI. That being said, I have some <code>Flashcards</code> that I'm flipping. The problem is, when I use <code>withAnimation { }</code>, there's some lag that sometimes makes it look like the card isn't even flipping (it looks like just the content inside the card instantly changes). I have 5 flashcards in a ScrollView rendered at the same time. How can I use <code>UIView.animate()</code> to animate the change?</p>
  <pre><code>struct Flashcard&lt;Front, Back&gt;: View where Front: View, Back: View {
      var front: () -&gt; Front
      var back: () -&gt; Back
      
      @State var flipped: Bool = false
      
      @State var flashcardRotation = 0.0
      @State var contentRotation = 0.0
      
      init(@ViewBuilder front: @escaping () -&gt; Front, @ViewBuilder back: @escaping () -&gt; Back) {
          self.front = front
          self.back = back
      }
      
      var body: some View {
          ZStack {
              if flipped {
                  ZStack {
                      back()
                      VStack {
                          HStack {
                              Spacer()
                              Button(action: {
                                  flipFlashcard()
                              }, label: {
                                  Text(&quot;Flipper&quot;)
                              }).padding(5)
                          }
                          Spacer()
                      }
                  }
              } else {
                  ZStack {
                      front()
                      VStack {
                          HStack {
                              Spacer()
                              Button(action: {
                                  flipFlashcard()
                              }, label: {
                                  Text(&quot;Flipper&quot;)
                              }).padding(5)
                          }
                          Spacer()
                      }
                  }
              }
          }
          .rotation3DEffect(.degrees(contentRotation), axis: (x: 0, y: 1, z: 0))
          .frame(height: 150)
          .frame(maxWidth: .infinity)
          .padding(.horizontal)
          .rotation3DEffect(.degrees(flashcardRotation), axis: (x: 0, y: 1, z: 0))
      }
      
      func flipFlashcard() {
          let animationTime = 0.25
  //        My attempt at using UIView.animate()
  //        UIView.animate(withDuration: 5, animations: {
  //            flashcardRotation += 180
  //        })
  
          withAnimation(Animation.linear(duration: animationTime)) {
              flashcardRotation += 180
          }
  
  //        My attempt at using UIView.animate()
  //        UIView.animate(withDuration: 0.001, delay: animationTime / 2, animations: {
  //            contentRotation += 180
  //            flipped.toggle()
  //        }, completion: nil)
          
          withAnimation(Animation.linear(duration: 0.001).delay(animationTime / 2)) {
              contentRotation += 180
              flipped.toggle()
          }
      }
  }
  </code></pre>