对于我的游戏逻辑,我必须锁定屏幕方向并设置由SwiftUI中的Button以编程方式触发的方向。我应该怎么办?
import SwiftUI
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")
}
}