SwiftUI Adaptive Layout
Discipline-enforcing skill for building layouts that respond to available space rather than device assumptions.
Overview
Covers tool selection (ViewThatFits vs AnyLayout vs onGeometryChange), size class limitations on iPad, iOS 26 free-form windows, and common anti-patterns that break in multitasking.
When to Use
- "How do I make this layout work on iPad and iPhone?"
- "Should I use GeometryReader or ViewThatFits?"
- "My layout breaks in Split View / Stage Manager"
- "Size classes aren't giving me what I need"
- "Designer wants different layout for portrait vs landscape"
- "Preparing app for iOS 26 window resizing"
- "Should my iPhone app look like iPad in a wide window?" (iOS 27)
- "What size classes does iPhone Duo report on its outer and inner displays?"
- "My scroll position / selection / draft is lost when the window resizes"
- "My form's Confirm button is clipped off-screen when the window is short"
- "Text lines are unreadably wide in a large window"
Key Patterns
Tool Selection
| I need to... | Use this |
|---|---|
| Pick between 2-3 layout variants | ViewThatFits |
| Switch H↔V with animation | AnyLayout |
| Read container size | onGeometryChange |
| Custom layout algorithm | Layout protocol |
| Keep non-shrinkable content reachable in small windows | ViewThatFits + ScrollView fallback |
| Cap text line length in wide windows | Readable-width frame idiom |
Anti-Patterns Prevented
UIDevice.current.orientation– Reports device, not windowUIScreen.main.bounds– Wrong in multitaskingUIDevice.current.userInterfaceIdiom == .pad– iPad in 1/3 Split View is narrower than iPhone- Unconstrained
GeometryReader— Greedy sizing breaks siblings - Size class as orientation proxy — iPad is
.regularin both orientations - Injecting
.regularto fake iPad on a wide iPhone window — a wide resizable iPhone window already reports.regular, and forcing it hides the tabs of a sidebar-adaptable tab view set to prefer a sidebar in narrow windows - Separate phone/tablet state trees — crossing the size-class boundary abandons scroll, selection, focus, and drafts; the skill maps each state type to the mechanism that survives adaptation
iOS 26 Changes
- Free-form window resizing – Users can drag to resize windows anywhere
UIRequiresFullScreendeprecated – Apps must handle resizing- Menu bar on iPad – Via SwiftUI
.commands - NavigationSplitView auto-adapts – Columns show/hide automatically
Related Resources
- swiftui-layout-ref – Complete API reference
- swiftui-debugging – View update diagnostics
- iPhone Duo – Size classes and layout across iPhone Duo's displays and poses
- WWDC 2025: Elevate the design of your iPad app
- WWDC 2024: Get started with Dynamic Type