How do I apply a perspective transform to a UIView?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
A perspective effect on UIView is done through the underlying layer transform, not through a separate high-level UIKit API. In practice, you build a CATransform3D, set its perspective component, then apply rotations or translations. The main thing to understand is that this creates a 3D projection effect, not an arbitrary four-corner image warp.
Use CATransform3D and Set m34
Perspective in Core Animation is controlled by the m34 element of the transform matrix. A small negative value gives the visual effect of depth.
Without m34, the rotation still happens, but it looks flat because there is no perspective projection.
Apply Perspective from a Container When Multiple Views Share It
If several sibling views should appear in the same 3D space, apply the perspective to the container layer's sublayerTransform instead of setting a separate perspective on each child.
This produces a more coherent scene because the children share one perspective projection.
Adjust the Anchor Point for Card-Flip Effects
By default, a view rotates around its center. For a book-opening or door-hinge effect, move the layer anchor point before applying the transform.
Changing the anchor point also changes positioning, so update the layer position deliberately. If you skip that step, the view often appears to jump.
Know the Limit of This Technique
Core Animation perspective transforms are great for rotations and depth effects, but they do not turn a UIView into a fully general perspective-warped quadrilateral. If you need each corner to move independently, you are in homography territory, which usually means a lower-level rendering approach.
That distinction matters because many questions use the phrase "perspective transform" to mean a freeform four-point warp. UIView layer transforms do not directly provide that abstraction.
For most interface work, that limit is acceptable. Card flips, cover-flow-style tilts, and panel reveals all fit well within the built-in layer transform model.
Animate the Transform Cleanly
Once the transform is correct, animation is straightforward.
The important part is to keep the m34 term in the animated target value. If you animate only the rotation and drop the perspective component, the effect changes midway.
Common Pitfalls
- Rotating a view in
CATransform3Dbut forgetting to setm34, which removes the perspective effect. - Applying separate perspective values to sibling views when they should share one 3D scene.
- Changing
anchorPointwithout correcting the layer position. - Expecting
UIViewtransforms to provide arbitrary four-corner warping. - Animating to a target transform that omits the original perspective component.
Summary
- Use
CATransform3Don the view's layer for perspective effects. - Set
m34to a small negative value to introduce depth. - Use a container
sublayerTransformwhen several views should share the same perspective. - Adjust
anchorPointfor hinge-style motion. - Use another rendering approach if you need a true freeform perspective warp.

