Force Landscape when orientation is locked

Buyin Brian

I am building a video app. When a user rotates the device to landscape, the video takes over all of the screen and the UI changes.

Is there a way to 'force' landscape layout when the device is in portrait? For example, if the user has orientation lock we want to add a button to enter the landscape mode. The YouTube app has a button that does this.

Reinier Melian

Yes you can force it using this 2 lines of code, in your viewDidAppear

    let value = UIInterfaceOrientation.landscapeLeft.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Force “landscape” orientation mode

Force landscape orientation in CSS

App force change orientation landscape to portrait when start purchase flow

Android: Force landscape orientation but allow rotation

Track device orientation when orientation is locked

Startup orientation when device orientation locked

UIWindow with wrong size when using landscape orientation

Hiding a view when orientation changes to landscape in autolayouts

Fragment not using landscape layout when orientation is changed

Q&A - How to force device orientation to rotate between landscape and portrait

Android App orientation locked to landscape, locking the device, rotate it to portrait and unlock it, Application crash

Orientation landscape not working properly in landscape

How to add scrolling to the view when screen orientation is changed to landscape?

HTML canvas breaking when keyboard is shown at landscape orientation

Map behavior changes when changed to landscape orientation using fragments

UIDevice orientation returns portrait when device launches as landscape

How to get landscape orientation when converting IPython notebook to PDF?

Different screen orientation on different devices when landscape mode

Landscape Orientation When Download Table HTML to PDF Using TableHTMLExport Plugin

UIPrintInteractionController appends a blank page when the orientation is set to Landscape

Making video fullscreen automatically when the device orientation is landscape with javascript

Admob SMART_BANNER in android is not working when orientation is in Landscape mode

android setting Orientation locked the orientation

Camera Orientation Change When Picture Taken. Even When Orientation is locked.

Landscape orientation file not running

Flutter landscape orientation layout

AVCaptureVideoPreviewLayer orientation - need landscape

Using UIImagePickerController in landscape orientation

lock iPad to landscape orientation