Swift 2.0中的supportedInterfaceOrientationsForWindow

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

在Swift 1.2中,这个代码是可行的,但现在return语句会报错:

二进制运算符'|'不能应用于两个'UIInterfaceOrientationMask'操作数

我可以使用新类型的一个返回值来使其工作,但我无法获得第二个所需的方向。

这个代码“可行”

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个或更多值吗?

1个回答

6

尝试新语法:

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

1
好奇你是怎么想出来的! - Aggressor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接