如何在 iOS 中以编程方式锁定屏幕方向?
你可能会遇到需要将 UI 显示在特定方向(可能是横屏或竖屏)的情况下。
我们将了解如何使用 iOS 中的 Swift 以编程方式锁定方向。
打开 Xcode → 新项目 → ViewController.swift 编写以下代码。
// Set the shouldAutorotate to False
override open var shouldAutorotate: Bool {
return false
}
// Specify the orientation.
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP