Screen rotation support in iOS means designing an app so that its UI automatically adjusts when the device changes orientation:
👉 A well-designed app looks good and works properly in both modes.
The direction in which the device is held:
Help adapt UI for different screen sizes and orientations
Example:
Device Rotates
↓
iOS detects orientation change
↓
Layout updates using Auto Layout / Size Classes
↓
UI adapts to new screen size
In Xcode:
Go to Target → General → Deployment Info
Enable:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [.portrait, .landscapeLeft, .landscapeRight]
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
if size.width > size.height {
print("Landscape Mode")
} else {
print("Portrait Mode")
}
}
if UIDevice.current.orientation.isLandscape {
print("Landscape")
} else {
print("Portrait")
}
Automatically rearrange elements:
if UIDevice.current.orientation.isLandscape {
label.font = UIFont.systemFont(ofSize: 24)
} else {
label.font = UIFont.systemFont(ofSize: 18)
}
Draw:
Portrait Mode Landscape Mode
📱 📱
| App | | App |
| UI | | UI Layout |
|_____| |___________|
Portrait:
Landscape:
👉 Layout changes automatically based on orientation
Screen rotation = switching between portrait & landscape
iOS automatically adjusts UI using:
Key methods:
viewWillTransitionUIDevice orientationAlways design responsive UI
Test both orientations for best results
Open this section to load past papers