【问题标题】:UIKeyCommand discoverabilityTitle deprecatedUIKeyCommand 可发现性标题已弃用
【发布时间】:2019-11-22 07:31:36
【问题描述】:

根据documentation 便利初始化器discoverabilityTitle 现在已弃用:

    // 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)

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

【问题讨论】:

    标签: swift ios13 uikeycommand


    【解决方案1】:

    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)
    }
    

    【讨论】:

    • 在当前的测试版中是否会崩溃?
    • beta 4 对我来说确实崩溃了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-31
    • 2012-05-02
    • 1970-01-01
    • 2012-03-18
    • 2014-02-12
    • 2018-05-09
    相关资源
    最近更新 更多