I want to deactivate the button until the animation is finished. I want it to be active when the animation is over.
I wrote the following, but it didn't work. It activates immediately.
import SwiftUI
struct ContentView: View {
@State private var scale: CGFloat = 1
@State private var isDisable = false
var body: some View {
VStack {
Button(
action: {
isDisable = true
withAnimation(
.linear(duration: 1)
) {
scale = scale - 0.1
isDisable = false
}
},
label: {
Text("Tap Me")
}
)
.disabled(
isDisable
)
RectangleView().scaleEffect(
scale
)
}
}
}
struct RectangleView: View {
var body: some View {
Rectangle().fill(
Color.blue
)
.frame(
width:200,
height: 150
)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}