I’d love any help understanding why the buttons change the variable but don’t actually change the speed of the animation.
struct _2animation: View {
@State private var isRotating = true
@State private var speed0 = 5.5
var body: some View {
VStack {
Spacer()
Image("Layer0")
.resizable()
.frame(width: 200, height: 200)
.rotationEffect(.degrees(isRotating ? 360 : 0))
.animation(.linear(duration: speed0).repeatForever(autoreverses: false), value: isRotating)
Spacer()
// not sure why these buttons don't do anything
HStack {
Button("fast") {
speed0 = 2.0
}
Button("slow") {
speed0 = 10.0
}
}
Spacer()
Text("\(speed0)")
Spacer()
}
.onAppear {
isRotating = false
}
}
}