How to present view controller from right to left in iOS using Swift
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
UIKit's default modal animation slides a view controller up from the bottom, but many apps want a horizontal transition that feels closer to a navigation push. To present from right to left, the standard solution is a custom modal transition using a transitioning delegate and animator objects.
Understand the Pieces of a Custom Transition
A custom modal presentation has three moving parts:
- the presented view controller
- a transitioning delegate
- animator objects for presentation and dismissal
The delegate acts as a factory for animation behavior, while the animator performs the actual frame changes. Keeping these responsibilities separate makes the transition reusable across screens.
Create a Right-to-Left Animator
The animator below handles both presentation and dismissal. Presentation starts off-screen to the right. Dismissal moves the current view back to the right.
This is enough for a basic reusable horizontal modal transition.
Provide the Animator Through a Transitioning Delegate
The transitioning delegate returns one animator for presentation and another for dismissal.
This keeps transition setup small in the presenting controller and makes the animation logic easy to share.
Present the Destination Controller Correctly
To use the custom transition, set modalPresentationStyle to .custom, assign the transitioning delegate, and then call present.
The presenting controller must keep a strong reference to the transitioning delegate. If it is created as a temporary local variable, the system may fall back to the default transition.
When This Is Better Than a Navigation Push
If the screen is conceptually a modal task but you still want horizontal motion, this approach makes sense. For example:
- settings or filter screens presented over the current flow
- onboarding steps shown modally
- temporary detail flows that should dismiss back to the origin
If the destination is actually part of a standard hierarchical navigation stack, a UINavigationController push is usually the simpler and more native choice.
Optional: Add Interactive Dismissal Later
If the design calls for swipe-to-dismiss behavior, you can extend the transition with UIPercentDrivenInteractiveTransition. That is useful, but it also adds gesture coordination and more edge cases. It is worth adding only when the product flow specifically benefits from interactive dismissal.
Common Pitfalls
The most common mistake is forgetting to set modalPresentationStyle = .custom. Without that, UIKit ignores the custom animator and uses the default modal transition.
Another issue is creating the transitioning delegate as a local variable that gets deallocated before the animation runs. Store it as a property on the presenting controller.
Developers also sometimes mix modal custom transitions and navigation pushes in the same conceptual flow without a clear reason. That creates motion that feels inconsistent.
Finally, test rotation, safe area behavior, and iPad presentation. Frame-based animation that looks good in one layout can be awkward in another if you never validate the final frames.
Summary
- Use a custom animator and transitioning delegate to present a controller from right to left.
- Set
modalPresentationStyleto.custombefore presenting. - Keep the transitioning delegate alive as a strong property.
- Implement both presentation and dismissal so the motion feels complete.
- Use this pattern for modal flows that need horizontal motion, not as a replacement for normal navigation pushes.

