I have this animation code:
struct CheckmarkAnimation: View {
@State private var isAnimating = false
var body: some View {
ZStack {
Circle()
.trim(to: isAnimating ? 1:0)
.stroke(.green, lineWidth: 3)
.frame(width: 100, height: 100)
.animation(.easeInOut(duration: 1), value: isAnimating)
Image(systemName: "checkmark")
.foregroundColor(.green)
.font(.largeTitle)
.scaleEffect(isAnimating ? 1.5 : 0)
.animation(.spring(response: 0.5, dampingFraction: 0.4).delay(1), value: isAnimating)
}
.onAppear {
isAnimating.toggle()
}
}
}
I would like this view to disappear after the scaling effect on the checkmark ends. How do I do this?
2
Answers
.scaleEffect() on ZStack is an elegant solution.
This code works and makes the view disappear^^
Here are 2 ways to do it:
Change drawing color to
.clear
after 2 secondsHere’s a way to have it disappear (turn invisible but still take up space). Change the drawing color to
.clear
after 2 seconds:Use
.scaleEffect()
onZStack
Insert this scale animation before the
.onAppear
:Note: Use
0.001
instead of0
inscaleEffect
to avoidmessages in the console.