【问题标题】:swift few UIKeyCommand on a key在一个键上快速几个 UIKeyCommand
【发布时间】:2022-08-05 06:48:01
【问题描述】:

我想处理键盘上的 \"enter\" 键:

  • 只有 \"enter\" - 发送功能
  • enter + shift/option - 换行功能

但是如果在没有修饰符的情况下设置输入句柄,那么修饰符移位/选项将重置

如何使用 shift/option 仅处理 \"enter\" 键和 \"enter\" ?

open override var keyCommands: [UIKeyCommand]? {
    let commands = [UIKeyCommand(input: \"\\r\", modifierFlags: [.control, .alternate], action: #selector(newLineKey)),
                    UIKeyCommand(input: \"\\r\", modifierFlags: [], action: #selector(sendKey(sender:)))]
    if #available(iOS 15, *) {
        commands.forEach { $0.wantsPriorityOverSystemBehavior = true }
    }
    return commands
}

例如:如果我按shift + enter 然后调用sendKey 函数而不是newLineKey

    标签: swift uikeycommand


    【解决方案1】:

    你找到解决方案了吗?我有同样的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-31
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 2016-09-18
      相关资源
      最近更新 更多