swift - Swift 2.0 中的 supportedInterfaceOrientationsForWindow

标签 swift swift2 appdelegate uiinterfaceorientation

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
    return UIInterfaceOrientationMask.Portrait.rawValue.hashValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue.hashValue
}

这曾经在 Swift 1.2 中有效,但返回行现在抛出此错误:

Binary operator '|' cannot be applied to two 'UIInterfaceOrientationMask' operands

我能够使用新类型仅使用 1 个返回值,但我无法让它通过管道传输我需要的第二个方向。

这个“有效”

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
  return UIInterfaceOrientationMask.Portrait 
}

但我“认为”我需要的是:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
{
  return UIInterfaceOrientationMask.Portrait | UIInterfaceOrientationMask.PortraitUpsideDown
}

它说的错误与我在上面发布的错误相同。

您知道如何在 Swift 2.0 的 AppDelegate 中将方向正确设置为 2 个或更多值吗?

最佳答案

尝试新语法:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
  return [.Portrait, .PortraitUpsideDown]
}

关于swift - Swift 2.0 中的 supportedInterfaceOrientationsForWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32634110/

相关文章:

ios - AVPlayer 元数据图稿不显示在 tvOS 上

ios - 提示对运动与健身数据的许可

ios - 如何在 Swift 中编写通用的 apply() 函数?

ios - 具有 0 行的 UILabel 最初不显示全文

swift - TableView heightForRowAtIndexPath 返回不正确的部分

xcode - Swift 2 字符串和 NSURL 错误

ios - 我如何与 AppDelegate 的特定 View 进行交互?

objective-c - 如何在测试用例中使用 AppDelegate?

swift 2 : Path of image in sqlite manager not showing up on iphone device

Swift - 如何从对象数组创建字符串数组