如何使用UIInterfaceOrientationMask

2 iphone uiinterfaceorientation swift ios8

我一直在尝试在我的Swift代码中使用UIInterfaceOrientationMask.在Objective-C中,我会将它用作枚举,当我需要使用例如肖像蒙版时,我会UIPortraitOrientationMask在我的代码中使用,如下所示:

NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
Run Code Online (Sandbox Code Playgroud)

我不太确定我应该对文档做什么,而且我无法在教程书或文档中的任何地方找到任何关于"原始选项集"的内容.在此输入图像描述

emr*_*s57 7

从Xcode 7开始,Swift 2.0版:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask.Portrait }
Run Code Online (Sandbox Code Playgroud)

原来过时的答案如下:

从Xcode 6.2或6.3或Swift 1.2版开始:

override func supportedInterfaceOrientations() -> Int { return Int(UIInterfaceOrientationMask.Portrait.rawValue) }
Run Code Online (Sandbox Code Playgroud)

supportedInterfaceOrientations被定义为返回Int,但是UIInterfaceOrientationMask是枚举.因此,使用rawValue枚举的属性来查找其原始值,这将给出一个UInt.Int()函数将UInt作为输入并返回Int.