Swift 2.0中的supportedInterfaceOrientationsForWindow [英] supportedInterfaceOrientationsForWindow in Swift 2.0

查看:337
本文介绍了Swift 2.0中的supportedInterfaceOrientationsForWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

曾经在Swift 1.2中工作过,但是返回行现在抛出此错误:

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

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

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

使用新类型,我只能使用1个返回值,但无法将其传递给所需的第二个方向.

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.

这个可行"

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

但是我需要的是:

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

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

And it says the same error as I posted above.

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

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

推荐答案

尝试新语法:

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

这篇关于Swift 2.0中的supportedInterfaceOrientationsForWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆