I would like to make an animation that is like this: a ZStack with a view and over it, a purple rectangle, that initially has scale 0 and opacity 0 and is at the center of screen.
When the animation is triggered, two animations happen:
- the rectangle's scale increases from 0 to 1 in 0.4 seconds.
- the rectangle's opacity increases from 0 to 1 in 0.3 seconds and from 1 to 0 in 0.1 seconds.
This is me trying to do this:
struct ContentView : View { @State private var scale: CGFloat = 0 @State private var scaleSeed: CGFloat = 0.1 @State private var counter: Int = 1 @State private var triggerFlashAnimation = false { didSet { scale = 0 counter = 1 } } var body: some View { ZStack { Text("Hello") if triggerFlashAnimation { Rectangle() .background(Color.purple) .scaleEffect(scale) .onAppear { scale += scaleSeed counter += 1 } } } I think this will animate the scale but this is very crude as I don't have any control over time.
I remember back in the day of CoreGraphics that you could define keyframes for time and values.
How do I do that with SwiftUI. I mean a precise animation defining keyframes and values for every parameter?
I googled around and found nothing.