How do I force my device into landscape orientation on tap of a button using SwiftUI
Device Orientation
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")
}
}