Rotation methods deprecated, equivalent of 'didRotateFromInterfaceOrientation'?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you used didRotateFromInterfaceOrientation in older UIKit code, the modern replacement is not a one-for-one method with the same timing. Apple’s current approach is size-transition driven, with Auto Layout, trait collections, and viewWillTransition(to:with:) handling most of the work that older orientation callbacks used to manage manually.
Why the Old Rotation Methods Were Deprecated
Earlier iOS APIs exposed rotation as a direct orientation event. That matched a simpler world of phones, full-screen apps, and manual frame calculations.
Modern UIKit has to support much more:
- Auto Layout instead of manual frame math
- split view and multitasking on iPad
- size class changes that are not simple portrait-versus-landscape flips
- container view controllers that coordinate transitions
Because of that, UIKit now models the event as a size transition rather than “the device rotated.” In other words, your code should react to the new layout environment, not to a specific orientation callback.
The Main Replacement: viewWillTransition(to:with:)
For most cases, the method you want is viewWillTransition(to:with:).
The important detail is the transition coordinator. If you need code that runs after the rotation or resize animation completes, put it in the completion block. That is the closest modern equivalent to the old “did rotate” timing.
When Auto Layout Is Enough
A large amount of old rotation code no longer needs any direct replacement at all. If your layout is constraint-based and your views adapt correctly, the best solution is often to delete the old rotation logic.
Examples that usually should be handled by constraints instead of manual rotation code:
- resizing a table view to fill the screen
- centering a button after rotation
- moving labels when width changes
- switching stack spacing for compact versus regular layouts
When the layout is described correctly through constraints, the system applies the transition and your code stays smaller.
Use Trait Changes for Environment-Specific Behavior
Some UI changes are really about size classes or interface environment, not about rotation itself. In those cases, checking traits can be more expressive than checking whether the device is in landscape.
This matters because a size-class change can happen without a classic rotation event, especially on iPad.
If You Need the “After Rotation” Moment
A common complaint is that viewWillTransition(to:with:) sounds like a “before” callback, while didRotateFromInterfaceOrientation was clearly “after.” The transition coordinator solves that gap.
Use the coordinator’s completion block for work that depends on the final geometry being settled. For example:
- scrolling to a corrected content offset
- recalculating a custom drawing path
- restarting an animation that depends on final bounds
- invalidating a complex collection view layout
That is the practical replacement pattern, not a separate viewDidTransition API.
Avoid Device Orientation As a Layout Driver
Many legacy codebases ask UIDevice.current.orientation and branch into portrait or landscape logic. That is usually weaker than reacting to the actual view size. Device orientation can be unknown, face-up, or irrelevant when the interface is not full-screen.
If your layout decision is really “is the available width wide enough for a two-column view,” then measure width or size classes directly. That produces more robust UI code than orientation-specific branching.
Common Pitfalls
The most common mistake is searching for a direct replacement with the same semantics as didRotateFromInterfaceOrientation. Modern UIKit expects you to think in terms of transitions and layout, not orientation callbacks.
Another common problem is putting expensive layout code directly into viewWillTransition without using the transition coordinator. If the work depends on the final frame, run it in the completion block.
Developers also often keep manual frame code that fights Auto Layout. If constraints already describe the intended layout, manual adjustments can cause flicker or conflicting results.
Finally, avoid using device orientation as the primary source of truth for interface changes. The actual container size is usually what matters.
Summary
- The modern replacement for old rotation callbacks is usually
viewWillTransition(to:with:). - Use the transition coordinator completion block when you need “after rotation” timing.
- Prefer Auto Layout and trait-based adaptation over manual orientation code.
- React to size and environment changes, not just portrait-versus-landscape assumptions.
- In many cases, the correct replacement is simply removing old rotation code and letting constraints handle the layout.
Related reading
- Round corner for BottomSheetDialogFragment
- round trip Swift number types to/from Data
- Round two corners in UIView
- Rounded corner for textview in android
- Rounding a double value to x number of decimal places in swift
- Run react-native application on iOS device directly from command line?
- Run/install/debug Android applications over Wi-Fi?
- Run/install/debug Android applications over Wi-Fi?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.