【问题标题】:Slow Buttons with Custom Keyboard Extension带有自定义键盘扩展的慢速按钮
【发布时间】:2018-04-01 09:09:08
【问题描述】:

我们制作了一个自定义键盘并上传到 App Store,设计和键盘工作正常。然而,由于按钮速度慢,我们得到了很多 1 星评价。问题是。有没有办法加快UIButtons 的速度?

UIControl 的 touchUpInside 在用户将手指从按钮上松开后就可以工作,在某些情况下人们写得太快了,touchUpInside 不是“快速”的方式来做到这一点

TouchDown 将在TouchUpInside 之前触发,因为触摸是您的手指在手机上触摸的动作。

请就此提供建议,您通常更喜欢哪种方式和哪种方式用于生产键盘

这是我目前处理水龙头的方法:太慢了!

func buttonAction(_ sender:UIButton!) {
        print("Button tapped")
       self.textDocumentProxy.insert("B")
}

【问题讨论】:

  • Apple 的默认键盘会在触摸时注册一个键。但是,在 iPhone 上,如果在第一个键按下时按下了第二个键,那么第一个键就会被注册,并且不会等待它的触摸。这使输入保持在触地顺序中。你的键盘是这样工作的吗?
  • 是的,@vacawama。
  • 请记住,按下的键应该首先注册前一个。

标签: ios swift ios-keyboard-extension


【解决方案1】:

加快使用调度队列的最简单方法

     DispatchQueue.main.async { 
       self.textDocumentProxy.insertText(self.currentTitle!)}

我这样做并获得了与原始键盘一样的速度

【讨论】:

    【解决方案2】:

    TouchDown 与 TouchUpInside 的速度并不是真正的问题。当用户用双拇指打字并且击键顺序被错误解释时,问题就出现了。

    Apple 的默认键盘会在触摸时注册一个键。但是,在 iPhone 上,如果在第一个键按下时按下了第二个键,那么第一个键就会被注册,并且不会等待它的触摸。这将输入保持在触摸向下顺序(用于两个拇指打字),但仍反映触摸向上行为。

    要实现这一点,您需要同时观察 TouchDown 和 TouchUpInside 事件。

    这是您可以做到的一种方法。创建一个名为pendingButton 的属性来跟踪按下的最后一个按钮,并在松开按钮或按下另一个按钮时处理该按钮。

    您需要将buttonDown 连接到TouchDown 事件,并将buttonUp 连接到TouchUpInside 事件。

    // last button pressed down
    var pendingButton: String?
    
    // connect button TouchDown events here    
    @IBAction func buttonDown(_ sender: UIButton) {
        // If we already have a pending button, process it before storing
        // the next one
        if let pending = self.pendingButton {
            self.textDocumentProxy.insert(pending)
        }
        self.pendingButton = sender.currentTitle
    }
    
    // connect button TouchUpInside events here   
    @IBAction func buttonUp(_ sender: UIButton) {
        // If the button being let up is the latest pending button,
        // then process it, otherwise ignore it
        if sender.currentTitle == self.pendingButton {
            self.textDocumentProxy.insert(self.currentTitle!)
            self.pendingButton = nil
        }
    }
    

    注意:您可能还需要仔细考虑其他事件,例如 TouchUpOutside。这可能也应该连接到buttonUp,具体取决于您的键盘所需的行为。

    如果相反,在按钮外部拖动会取消该按钮,那么您应该实现一个函数来观察 TouchDragExit,然后如果该按钮是待定按钮,则取消该待定按钮。

    // connect button TouchDragExit events here
    @IBAction func dragExit(_ sender: UIButton) {
        if sender.currentTitle == self.pendingButton {
            self.pendingButton = nil
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 2020-03-19
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多