iOS: Why touchesBegan has some delay in some specific area in UIView

一笑奈何 提交于 2019-12-08 18:53:16

问题


I'm making an 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.


回答1:


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
}



回答2:


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.*/


来源:https://stackoverflow.com/questions/33727638/ios-why-touchesbegan-has-some-delay-in-some-specific-area-in-uiview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!