Skip to navigation

Handle orientation changes

Learn how to update your custom player layout when the device orientation changes.

When building a custom player UI, you need to handle orientation transitions to keep your controls properly positioned in both portrait and landscape modes.

Update layout on rotation

Override viewWillTransition(to:with:) to adjust your player constraints during rotation:

override func viewWillTransition(
to size: CGSize,
with coordinator: UIViewControllerTransitionCoordinator
) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { _ in
self.updatePlayPauseConstraintsForOrientation()
self.view.layoutIfNeeded()
})
}

Detect the current orientation

Use the following helper to check whether the device is in landscape mode:

private func isLandscapeMode() -> Bool {
if #available(iOS 13.0, *) {
let orientation = view.window?.windowScene?.interfaceOrientation
return orientation == .landscapeLeft || orientation == .landscapeRight
} else {
return UIApplication.shared.statusBarOrientation.isLandscape
}
}

Use this helper to adjust control positions, padding, or layout constraints based on the current orientation.