不推荐使用UIKeyCommand discoverabilityTitle

时间:2019-07-12 13:59:23

标签: swift ios13 uikeycommand

根据discoverabilityTitle的{​​{3}}便捷初始化程序已被弃用:

    // Key Commands with a discoverabilityTitle _will_ be discoverable in the UI.
    @available(iOS, introduced: 9.0, deprecated: 13.0)
    public convenience init(input: String, modifierFlags: UIKeyModifierFlags, action: Selector, discoverabilityTitle: String)

现在创建用户可发现按键命令的替代方法是什么?

1 个答案:

答案 0 :(得分:0)

iOS 13中引入了新的扩展初始化程序:

@available(iOS 13.0, *)
extension UIKeyCommand {

    /// Initializes a key command with extra properties.
    ///
    /// - Parameters:
    ///   - title: Short display title. This should be localized.
    ///   - action: Action to execute on choosing this command.
    ///   - input: Keys that must be pressed to choose this command.
    ///   - modifierFlags: Bit mask of key modifier flags to choose this command.
    ///   - propertyList: Property list object to distinguish commands, if needed.
    ///   - alternates: Alternates that differ in modifier flags, if needed.
    ///   - image: Image that can appear next to the command, if any.
    ///   - discoverabilityTitle: Elaborated title, if any.
    ///   - isEnabled: Whether to enable or disable the command.
    ///   - state: State that can appear next to the command.
    public convenience init(title: String, action: Selector, input: String, modifierFlags: UIKeyModifierFlags = [], propertyList: Any? = nil, alternates: [UICommandAlternate] = [], image: UIImage? = nil, discoverabilityTitle: String? = nil, isEnabled: Bool = true, state: UIMenuElement.State = .off)
}