> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://fastpix.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fastpix.com/docs/_mcp/server.

# Handle orientation changes

> Learn how to update your custom player layout when the device 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:

```swift
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:

```swift
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.