ios – SwiftUI find out how to keep away from delay() through the reversing state of an animation?

0
173


I need to implement a easy loading animation utilizing SwiftUI. The animation logic is as follows:

  1. Enlarge the primary circle, then return it to its unique dimension.
  2. Enlarge the second circle, then return it to its unique dimension.
  3. Enlarge the third circle, then return it to its unique dimension.
  4. Repeat steps 1-3 indefinitely.

Nonetheless, I’ve observed that if I exploit repeatForever(autoreverses: true) with delay(), there may be an undesirable delay when the animation is performed in reverse. How can I keep away from this delay through the reverse animation?

import SwiftUI

struct AnimationView: View {
    @State personal var scale: CGFloat = 1.0
    @State var animate = false
    
    var physique: some View {
        HStack {
            Circle()
                .scaleEffect(scale)
                .body(width: 20, top: 20)
                .animation(Animation.easeInOut(period: 1.0).delay(0).repeatForever(autoreverses: true), worth: animate)
            Circle()
                .scaleEffect(scale)
                .body(width: 20, top: 20)
                .animation(Animation.easeInOut(period: 1.0).delay(1).repeatForever(autoreverses: true), worth: animate)
            Circle()
                .scaleEffect(scale)
                .body(width: 20, top: 20)
                .animation(Animation.easeInOut(period: 1.0).delay(2).repeatForever(autoreverses: true), worth: animate)
        }
        .body(width: 400, top: 400)
        .onAppear {
            animate = true
            scale = 1.2
        }
    }
}



struct AnimationView_Previews: PreviewProvider {
    static var previews: some View {
        AnimationView()
    }
}