Swift 2.0 中的 supportedInterfaceOrientationsForWindow

supportedInterfaceOrientationsForWindow in Swift 2.0

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

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

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

我可以使用新类型仅使用 1 个 return 值,但我无法将其传输到我需要的第二个方向。

这个'works'

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

但是我'think'需要的是:

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]
}