【问题标题】:Rotation support issue with ios9?ios9的旋转支持问题?
【发布时间】:2015-10-26 18:05:58
【问题描述】:

我正在尝试在教科书中实现此功能,但它不起作用。这本书是在不同版本的 swift 上,所以这可能就是它不起作用的原因。我想知道是否有人知道如何解决这个问题?我正在使用迅速。

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

错误:方法没有“覆盖”其超类中的任何方法。 当我删除覆盖时,它给了我这个错误:
带有 Objective-C 选择器 'supportedInterfaceOrientations' 的方法 'supportedInterfaceOrientations()' 与具有相同 Objective-C 选择器的超类 'UIViewController' 中的方法 'supportedInterfaceOrientations()' 冲突

【问题讨论】:

标签: ios xcode swift ios9


【解决方案1】:

我认为 swift2 的方法是:

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

【讨论】:

    【解决方案2】:

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

    你想要的功能是

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 2013-01-13
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多