如何在 Swift 中打开/关闭 iPhone 纵向锁定

时间:2021-07-09 05:12:11

标签: ios swift iphone

我使用我的代码来设置屏幕的亮度。

UIScreen.main.brightness = CGFloat(0.5)

我可以使用该代码启用和禁用 iPhone 的屏幕方向锁定吗?

感谢大家的帮助!

onNewIntent

3 个答案:

答案 0 :(得分:0)

第 3 方应用程序无法操纵所有系统设置或其他应用程序设置,因为这可能会导致安全漏洞。这叫做沙盒。每个应用程序都有自己的“沙盒”,或者简单地说,一个无法访问/操纵系统设置或其他应用程序设置的监狱,这使得 Apple 设备真正安全。

虽然您可以使用

来操纵应用程序的方向
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}

答案 1 :(得分:0)

• 将 shouldAutorotate 设置为 False

 override open var shouldAutorotate: Bool {
    return false
 }

• 指定方向。

override open var supportedInterfaceOrientations:UIInterfaceOrientationMask {
    return .portrait
}

P.S:您可以在您的应用的屏幕上执行此操作,而不是在系统 (iPhone) 上。

答案 2 :(得分:0)

您可以使用它来更新设备方向:

UIDevice.current.setValue(UIDeviceOrientation.portrait.rawValue, forKey: "orientation")

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