I need to implement a easy loading animation utilizing SwiftUI. The animation logic is as follows:
- Enlarge the primary circle, then return it to its unique dimension.
- Enlarge the second circle, then return it to its unique dimension.
- Enlarge the third circle, then return it to its unique dimension.
- 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()
}
}