Device Orientation

How do I force my device into landscape orientation on tap of a button using SwiftUI

This should work:

struct ContentView: View {
    var body: some View {
        Button(action: {
            self.rotate()
        }) {
            Text("Rotate")
        }
    }

    func rotate() -> Void {
        let value = UIInterfaceOrientation.landscapeRight.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")
    }
}

Credit: https://stackoverflow.com/questions/61210549/how-to-set-ui-interface-orientation-programmatically-in-swiftui

Device Orientation
 
 
Q