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

后端 未结 5 1453
余生分开走
余生分开走 2021-01-06 03:38

I\'m experiencing an issue where the first call to touchesBegan:withEvent: on a UIView or UIViewController is delayed when you touch o

5条回答
  •  暖寄归人
    2021-01-06 04:11

    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;
    }
    

提交回复
热议问题