> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swiftui/view/state/animate.md).

# animate state changes

[SwiftUI](/ios/swiftui.md) ⟩ [view](/ios/swiftui/view.md) ⟩ [state](/ios/swiftui/view/state/value.md) ⟩ animate&#x20;

{% hint style="success" %}
Attach a [.animation(\_:value:) ](https://developer.apple.com/documentation/swiftui/view/animation\(_:value:\))modifier to the view you want to animate, and select an [Animation](https://developer.apple.com/documentation/swiftui/animation) as well as a [state value](/ios/swiftui/view/state/value.md) to monitor for changes.
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}

```swift
struct ContentView: View {

    // state value
    @State var isOn = false
    
    // view UI
    var body: some View {
        VStack {
            Circle()
                // view modifiers (change appearances)
                .frame(maxHeight: 200)
                .foregroundColor(isOn ? .red : .yellow)
                .scaleEffect(isOn ? 1.0 : 0.7)
                
                // ⭐️ view animation 
                .animation(.default, value: isOn)

            Button("Press Me") { isOn.toggle() }
        }
    }
}
```

{% endtab %}

{% tab title="👥 相關" %}

* [Animation](/ios/swiftui/anim/animation.md)：
  {% endtab %}
  {% endtabs %}
