Nothing Happens When Rotating An Image With Animation

Hi. What could be the issue with this piece of code? I only want the image to rotate 360 degrees non stop

var body: some View {
  HStack {
      Image(systemName: "arrow.clockwise")
        .rotationEffect(Angle.degrees(360), anchor: .center)
        .animation(
          .linear(duration: 1.5)
          .repeatForever(autoreverses: false),
          value: UUID()
        )
      Text("Downloading ...")
    }
}

Even without the value attribute in the .animation, no animation happens. Am i missing something else?

Accepted Answer

You have to tell SwiftUI when and what to animate. Currently, you have a static symbol image that has been rotated 360°, but hasn't been told to animate. Applying the animation(_:value:) modifier doesn't start the animation; it just tells SwiftUI what animation to do when the value changes.

Something like this should work:

@State private var rotationAngle: Double = 0

var body: some View {
    HStack {
        Image(systemName: "arrow.clockwise")
            .rotationEffect(.degrees(rotationAngle))
            .animation(.linear(duration: 1.5).repeatForever(autoreverses: false), value: rotationAngle)

        Text("Downloading ...")
    }
    .onAppear {
        rotationAngle = 360
    }
}
Nothing Happens When Rotating An Image With Animation
 
 
Q