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

查看:31
本文介绍了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 
}

但我认为"我需要的是:

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.

您知道如何在 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天全站免登陆