2015-10-26 56 views
1

我想在教科书中实现这个功能,它不工作。这本书是在不同版本的迅速,所以这可能是为什么它不工作。我想知道如果有人知道如何解决这个问题?我正在使用swift。ios9的旋转支持问题?

override func supportedInterfaceOrientations() -> Int { 
    return Int(UIInterfaceOrientationMask.Portrait.rawValue) | 
    Int(UIInterfaceOrientationMask.Landscape.rawValue) 
} 

错误:方法没有从它的超类中'覆盖'任何方法。 当我删除覆盖,它给我这个错误:
方法“supportedInterfaceOrientations()”与目标C选择“supportedInterfaceOrientations”与从超类的UIViewController“方法“supportedInterfaceOrientations()”以相同的目标C选择

冲突
+0

你有没有在这所采取偷看? http://iphonedev.tv/blog/2015/6/23/fix-uiviewcontroller-supportedinterfaceorientations-to-use-uiinterfaceorientationmask-and-optionsettype-in​​-swift-2 – Adrian

回答

2

我觉得swift2办法做到这一点是:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
    return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.Landscape] 
} 
1

你的函数的返回值类型是不一样的,在超类中定义的方法。 UIInterfaceOrientationMask是一个符合OptionSetType的swift结构。虽然其原始值是Int类型,但UIInterfaceOrientationMask是不同的类型,因为在swift中,返回类型是函数签名的一部分,所以实际上是在创建一个新函数,而不是覆盖现有类型。

你想要的功能是

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask