supportedInterfaceOrientationsForWindow in Swift 2

2019-05-11 07:18发布

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

That used to work in Swift 1.2 however the return line is now throwing this error:

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

I am able to get to work with just 1 return value with the new type but I cannot get it to pipe the second orientation I need.

This 'works'

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

But what I 'think' I need is this:

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

And it says the same error as I posted above.

Do you know how to properly set the orientation to 2 or more values in the in the AppDelegate in Swift 2.0?

1条回答
对你真心纯属浪费
2楼-- · 2019-05-11 08:02

Try new syntax:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
  return [.Portrait, .PortraitUpsideDown]
}
查看更多
登录 后发表回答