tezvyn:

Animate a SwiftUI Shape morphing point count

Source: interviewadvanced

WHAT IT TESTS: Driving custom interpolation with animatableData. OUTLINE: Expose a continuous sides value as animatableData so SwiftUI interpolates it, then compute the path from that fractional value each frame.

WHAT IT TESTS: Whether you understand that SwiftUI animates a single interpolatable value, not arbitrary paths. ANSWER OUTLINE: Make the Shape conform to Animatable and expose animatableData, usually a Double or an AnimatablePair, representing the parameter that drives the path, such as the number of sides. SwiftUI interpolates animatableData between old and new values across the animation, calling path(in:) repeatedly with intermediate fractional values, so you compute a polygon for any fractional side count.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Animate a SwiftUI Shape morphing point count · Tezvyn