func withAnimation <Result>(Animation?, () throws -> Result) rethrows -> Result
Overview 概要
You tell SwiftUI how to draw your app’s user interface for different states, and then rely on SwiftUI to make interface updates when the state changes. To avoid abrupt visual transitions when the state changes, add animation in one of the following ways:
Animate all of the visual changes for a state change by changing the state inside a call to the
with
global function.Animation(_: _:) Add animations to particular views when specific values change by applying the
animation(_:
view modifier.value:) Animate changes to a
Binding
by using the binding’sanimation(_:)
method.
SwiftUI animates the effects produced by many built-in view modifiers, like those that set a scale or opacity value. You can animate other values by making your custom views or view modifiers conform to the Animatable
protocol and telling SwiftUI about the value you want to animate.
When an animated state change results in adding or removing a view to or from the view hierarchy, you can tell SwiftUI how to transition the view into or out of place using built-in transitions defined by Any
, like slide
or scale
. You can also create custom transitions.