I am trying to animate an arrow to make it flip 180 degrees when a button is tapped. But it only works when I use the onTapGesture method with nothing else inside. It also does not work if I change the rotation angle value somewhere else in the code. For instance:
This piece of code is properly animated
Image(systemName: "arrow.up.circle")
.resizable()
.foregroundColor(.white)
.frame(width: 50, height: 50)
.rotationEffect(Angle.degrees(self.rotationAngle))
.animation(.easeIn, value: self.rotationAngle)
.onTapGesture {
self.rotationAngle += 180
}
This one is not
Image(systemName: "arrow.up.circle")
.resizable()
.foregroundColor(.white)
.frame(width: 50, height: 50)
.rotationEffect(Angle.degrees(self.rotationAngle))
.animation(.easeIn, value: self.rotationAngle)
.onTapGesture {
self.currentArrow.toggle()
self.rotationAngle += 180
}
Does anyone know why?