struct ScaleAnimateView: View {
@State private var isAnimated = false
var animation: Animation {
Animation.linear
}
var body: some View {
VStack(spacing: 20) {
// 1
Button("Rotate") {
self.isAnimated.toggle()
}
// 2
Rectangle()
.foregroundColor(.green)
.frame(width: 200, height: 200)
.scaleEffect(isAnimated ? 0.5 : 1)
.animation(animation)
}
}
}
Note: scaleEffect
should be placed before animation
.