`touchesBegan:withEvent:` is delayed at left edge of screen

五迷三道 提交于 2019-11-30 22:47:11

try adding this to the viewdidappear method. this might fix the issue. it happened with me as well but i got this code from stack overflow that fixed my issue. hope it helps you too

let window = view.window!
let gr0 = window.gestureRecognizers![0] as UIGestureRecognizer
let gr1 = window.gestureRecognizers![1] as UIGestureRecognizer
gr0.delaysTouchesBegan = false
gr1.delaysTouchesBegan = false

Purteeek solution seems to work nicely in my case too. This is an objective-C implementation for SpriteKit:

- (void)didMoveToView:(SKView *)view {

    UIGestureRecognizer* gr0 = view.window.gestureRecognizers[0];
    UIGestureRecognizer* gr1 = view.window.gestureRecognizers[1];

    gr0.delaysTouchesBegan = false;
    gr1.delaysTouchesBegan = false;

}

This doesn't mess with other gesture recognizers, and the system 3D Touch still works fine. I wonder why this is not the default behavior.

Like danialias I'm working on a game. The solution I found (currently working, tested on an iPhone with 3D Touch enabled, where this was a real issue up to this point..) works for both games/apps:

It seems that UITapGestureRecognizer doesn't suffer from this delay, so simply add one to your view, and use it to handle taps.

In my game, I store touches and handle them on every interval update, so I overrode

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

and there I stored the UITouch instance and returned NO.

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    [self.touches addObject:touch];
    return NO;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!