9

I'm making a custom keyboard and I'm in a really weird situation.

I've noticed that when I catch the event touchesBegan at the rear left (about 20 pixels) of the UIView (inputView), I'll have some delay in here. Any action I do in touchesBegan will be perform slower than other area.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
self.keypop.hidden = false
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
{
self.keypop.hidden = true
}

And this trouble affects my app's performance. In this example, I will not see the keypop appears when I touched on the rear left because self.keypop.hidden was delayed in showing up.

I don't know why, or is this an error from iOS 9? I've been stuck on this trouble for a week.

TomSawyer
  • 3,711
  • 6
  • 44
  • 79

2 Answers2

10

In my situation I was using touchBegan in a CollectionView and it was delaying touches when I tap Its worked with me by simply added this code

In Swift,

self.collectionView.delaysContentTouches = false
/*delaysContentTouches applies to all UIScrollView instances.*/
badhanganesh
  • 3,427
  • 3
  • 18
  • 39
Faisal Alneela
  • 166
  • 2
  • 8
8

The answer here seems to have fixed the same issue in our keyboard:

UISystemGateGestureRecognizer and delayed taps near bottom of screen

With the following code:

override func viewDidAppear(animated: Bool) {
    let window = view.window!
    let gr0 = window.gestureRecognizers![0] as UIGestureRecognizer
    let gr1 = window.gestureRecognizers![1] as UIGestureRecognizer
    gr0.delaysTouchesBegan = false
    gr1.delaysTouchesBegan = false
}
Community
  • 1
  • 1
BenB
  • 1,522
  • 1
  • 14
  • 26
  • This saved my life! I've been having this issue for a while now with a SpriteKit app where I sometimes need to do things at the top and bottom of the screen, but it always had weird behavior. – CodyMace Jan 10 '18 at 16:23
  • This works, but if you use gesture recognizers, instead, they seem to just work properly. For me (a SpriteKit game where I wanted touch-down to work), I used a long press with minimum duration set to 0, and triggered on state.began. Technique from https://stackoverflow.com/a/38143619/3937 – Lou Franco Feb 09 '20 at 15:56