2

I am making a keyboard extension, so I want caps lock to activate when shift is double tapped, and have it just regularly shift on single tap. My code:

var selector: Selector = "lockCapsLock"
var singleTapSelector: Selector = "shift"
let doubleTapRecognizer = UITapGestureRecognizer(target: self, action: selector)
let singleTapRecognizer = UITapGestureRecognizer(target: self, action: singleTapSelector)
singleTapRecognizer.numberOfTapsRequired = 1
doubleTapRecognizer.numberOfTapsRequired = 2
v.addGestureRecognizer(doubleTapRecognizer)
v.addGestureRecognizer(singleTapRecognizer)
singleTapRecognizer.requireGestureRecognizerToFail(doubleTapRecognizer)

The problem I'm having is that it takes too long when I single tap for it to fail the double tap, so there is a delay for pressing shift. If I too quickly press shift and then another key, it will come out lowercase, but then the next key will be shifted properly. Double tapping works properly.

How can I make the delay on single tapping less?

SomeGuy
  • 3,725
  • 3
  • 19
  • 23
  • I'd say you probably need to handle the shift/caps lock manually instead of using a gesture recognizer. If you watch the behavior of the built-in keyboard the shift button changes state *immediately* - it's not waiting to distinguish between single and double tap. Moreover, it should work when held down, too, right? – Nate Cook Oct 05 '14 at 04:01
  • That's very true. I thought there would be a more efficient way to do it with gesture recognizers, but I think you're probably right. – SomeGuy Oct 05 '14 at 04:54

0 Answers0