【问题标题】:How do I know/get the list of supported orientations for my iOS app?我如何知道/获取我的 iOS 应用程序支持的方向列表?
【发布时间】:2021-02-07 21:56:12
【问题描述】:
作为开发人员,我知道在我的 iOS 应用程序的项目设置/plist 中添加的方向列表,但我想知道代码中支持的方向列表。
例如,第 3 方 SDK 之一针对一种情况返回 UIInterfaceOrientationMask.landscapeLeft,我想在允许定向之前在我的视图控制器中对其进行验证。
如果我不这样做,我的应用程序就会崩溃,
崩溃 -> Supported orientations has no common orientation with the application
【问题讨论】:
标签:
ios
swift
screen-orientation
uiinterfaceorientation
uidevice
【解决方案1】:
我知道项目设置/plist 中添加的方向列表
对于我的 iOS 应用程序,但我想知道支持的列表
来自代码的方向。
您可以像这样从 info.plist 中获取支持的界面方向:
let orientations = Bundle.main.infoDictionary?["UISupportedInterfaceOrientations"]
然后您将获得可选值数组(如果您愿意,可以将其转换为字符串数组),如下所示:
▿ Optional<Any>
▿ some : 3 elements
- 0 : UIInterfaceOrientationPortrait
- 1 : UIInterfaceOrientationLandscapeLeft
- 2 : UIInterfaceOrientationLandscapeRight