如何在 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