簡體   English   中英

我如何知道/獲取我的 iOS 應用程序支持的方向列表?

[英]How do I know/get the list of supported orientations for my iOS app?

作為一名開發人員,我知道在我的 iOS 應用程序的項目設置/plist 中添加的方向列表,但我想從代碼中了解支持的方向列表。

例如,第 3 方 SDK 之一正在為一個場景返回UIInterfaceOrientationMask.landscapeLeft ,我想在允許方向之前在我的視圖控制器中驗證它。

如果我不這樣做,我的應用程序就會崩潰,

崩潰 -> Supported orientations has no common orientation with the application

我知道在我的 iOS 應用程序的項目設置/plist 中添加的方向列表,但我想從代碼中知道支持的方向列表。

您可以像這樣從 info.plist 中獲取支持的界面方向:

let orientations = Bundle.main.infoDictionary?["UISupportedInterfaceOrientations"]

然后您將獲得可選值數組(如果需要,您可以將其轉換為字符串數組),如下所示:

▿ Optional<Any>
  ▿ some : 3 elements
    - 0 : UIInterfaceOrientationPortrait
    - 1 : UIInterfaceOrientationLandscapeLeft
    - 2 : UIInterfaceOrientationLandscapeRight

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM