Question: Using SwiftUI, I'm trying to show an animated image and hide the text when the user clicks the button. Here is my code:

```
@State private var showingActivity = false

var body: some View {
    Button(action: {
        self.showingActivity.toggle()
    }) { 
        HStack {
            if self.showingActivity {
                Image(systemName: "arrow.2.circlepath")
                    .font(.system(size: 29))
                    .rotationEffect(.degrees(self.showingActivity ? 360.0 : 0.0))
                    .animation(Animation.linear(duration: 1.5).repeatForever(autoreverses: false))
            }
            else {
                Text("Continue")
            }
        }
    }
}

```

The **Continue** text appears and when clicked it disappears (as expected) and the image shows, but no animation. Any ideas what I might be doing wrong.

Thanks

Answer: 
or try this:

```
struct ImageView : View {

    @State private var showAction = false

    var body: some View {
        Image(systemName: "arrow.2.circlepath")
            .font(.system(size: 29))
            .rotationEffect(.degrees(self.showAction ? 360.0 : 0.0))
            .animation(self.showAction ? Animation.linear(duration: 1.5).repeatForever(autoreverses: false) : nil)
        .onAppear() {
            self.showAction = true
        }
    }
}

struct ContentView: View {
    @State private var showingActivity = false

    var body: some View {
        Button(action: {
            self.showingActivity.toggle()
        }) {
            HStack {
                if self.showingActivity {
                    ImageView()
                }
                else {
                    Text("Continue")
                }
            }
        }
    }
}

```
You can use `.opacity` instead of `if...else` statements, in this case rotation works on image. But in canvas I still see some glitches, if tap button several times but I didn't try on real device (behavior there can be other). Hope it'll help:

```swift
struct AnimatableView: View {
    @State private var showingActivity = false

    var body: some View {
        Button(action: {
            self.showingActivity.toggle()
        }) {
            ZStack {
                Image(systemName: "arrow.2.circlepath")
                    .font(.system(size: 29))
                    .rotationEffect(.degrees(self.showingActivity ? 360.0 : 0.0))
                    .animation(Animation.linear(duration: 1.5).repeatForever(autoreverses: false))
                    .opacity(self.showingActivity ? 1 : 0)

                Text("Continue")
                    .opacity(self.showingActivity ? 0 : 1)

            }

        }
    }
}

```