How can I animate the movement of a view or image along a curved path?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Animating a view or image along a curve is usually easier if you think in terms of a path instead of hand-calculating intermediate coordinates. On Apple platforms, the standard solution is to build a UIBezierPath and feed it to a keyframe animation.
Use a Path, Not Manual Frames
If you move a view by repeatedly changing frame.origin, you have to invent the curve math yourself. A path-based animation is cleaner because the curve shape is described once and Core Animation handles interpolation.
Here is a basic example that moves an UIImageView along a quadratic-style arc:
This creates the visual motion, but there is an important caveat: it animates the presentation layer, not the model layer's stored position.
Keep the Final Position in Sync
If you only add the animation, the image may snap back later when the layer redraws. To avoid that, update the real position too.
That keeps the view's underlying state aligned with what the user saw.
Rotate Along the Curve
If you want the image to face the direction of travel, set the rotation mode:
This works well for icons such as arrows, planes, or cars. For symmetric images such as circles, the rotation may not matter.
When to Use Keyframes vs Physics
Path animation is ideal when the motion is predetermined, like a tutorial hint, a send animation, or a decorative transition. If the motion depends on live user dragging, collision, or inertia, a physics-based approach is often more appropriate.
In other words:
- use a path when you know the route ahead of time
- use gesture or physics systems when the route emerges from interaction
You can also combine both approaches. For example, a drag interaction may decide the destination, and then a path animation can take over for the polished final travel arc.
Common Pitfalls
- Animating only the layer presentation and forgetting to update the actual view position.
- Using
frame.originwhenpositionorcenteris the property being animated. - Expecting Auto Layout constraints to respect the animation automatically. If constraints control the final position, update them too.
- Drawing a path in the wrong coordinate space. The path points must match the animated layer's parent coordinate system.
Summary
- A curved motion animation is easiest with
UIBezierPathandCAKeyframeAnimation. - Animate the
positionkey path for smooth movement along the path. - Update the view's real final position so it does not snap back later.
- Use
rotationModeif the image should face the direction of travel. - Prefer path animation for predetermined motion and physics for interactive motion.

