supportedInterfaceOrientationsForWindow in Swift 2.0

筅森魡賤 提交于 2019-12-22 09:37:02

问题


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:


Try new syntax:

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


来源:https://stackoverflow.com/questions/32634110/supportedinterfaceorientationsforwindow-in-swift-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!