可以成为焦点 swift 3

canBecomeFocused on swift 3

我正在尝试创建一个我需要关注的自定义视图。 根据许多消息来源,这是要走的路:

override func canBecomeFocused() -> Bool {
    return true
}

但是在转换为 Swift 3.0 后,这不再有效。 它抛出错误:

Method does not override any method from its superclass.

如果我删除覆盖,则会引发另一个错误:

Method 'canbecomeFocused()' with Objective-C selector 'canBecomeFocused' conflicts with better for 'canBecomeFocused' from superclass 'UIView' with the same Objective-C Selector.

我可以为 TvOS 制作一个 UIView 可选的吗?

在Swift 3中改为Instance Property,所以这样试试。

override var canBecomeFocused: Bool {
    return true
}

查看 canBecomeFocused 上的 Apple 文档了解更多详细信息。