It means managing how an iOS app responds when the device changes orientation (Portrait ↔ Landscape) so that the UI remains usable and properly arranged.
It means restricting an app so it only works in selected orientations, such as:
Each view controller can define:
Device Rotates
↓
iOS detects orientation change
↓
View Controller updates layout
↓
Auto Layout rearranges UI
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")
}
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.verticalSizeClass == .compact {
print("Landscape detected")
}
}
if UIDevice.current.orientation.isLandscape {
label.font = UIFont.systemFont(ofSize: 24)
} else {
label.font = UIFont.systemFont(ofSize: 18)
}
Go to Xcode → Target → General
Deployment Info
Select allowed orientations:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return .portrait
}
👉 Forces entire app to portrait mode
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
👉 Only this screen stays in portrait
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscape
}
Rotate Device
↓
View Controller detects change
↓
UI rearranges using Auto Layout
App / Screen
↓
Allowed Orientation Rule
↓
Only Portrait OR Only Landscape
Portrait:
Landscape:
👉 Often forces landscape for better viewing
traitCollectionDidChange for modern appssupportedInterfaceOrientations used for?Rotation = switching between portrait & landscape
iOS handles rotation automatically using Auto Layout
Methods:
viewWillTransitiontraitCollectionDidChangeOrientation can be forced using:
Best practice: use adaptive UI, not fixed orientation
Open this section to load past papers