Contents

easeInOut(duration:)

An animation with a specified duration that combines the behaviors of in and out easing animations.

Declaration

static func easeInOut(duration: TimeInterval) -> Animation

Parameters

  • duration:

    The length of time, expressed in seconds, that the animation takes to complete.

Return Value

An ease-in ease-out animation with a specified duration.

Discussion

An easing animation provides motion with a natural feel by varying the acceleration and deceleration of the animation, which matches how things tend to move in reality. An ease in and out animation starts slowly, increasing its speed towards the halfway point, and finally decreasing the speed towards the end of the animation.

Use easeInOut(duration:) when you want to specify the time it takes for the animation to complete. Otherwise, use easeInOut to perform the animation for a default length of time.

The following code shows an example of animating the size changes of a Circle using an ease in and out animation with a duration of one second.

struct ContentView: View {
    @State private var scale = 0.5

    var body: some View {
        VStack {
            Circle()
                .scale(scale)
                .animation(.easeInOut(duration: 1.0), value: scale)
            HStack {
                Button("+") { scale += 0.1 }
                Button("-") { scale -= 0.1 }
            }
        }
    }
}

See Also

Getting eased animations