TouchsMoved is called with one click on the iPhone 6s and beyond.

I have a custom UIButton and I applied touch delegates in a custom button class.

Everything works fine up to the iPhone 6 Plus. All devices above it, such as the iPhone 6s and 7, pose a problem.

When I press the touchesBegan button, it is called as expected, but also calls touchesMoved and creates problems in my code.

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ _firstTouch = [[touches anyObject]locationInView:self]; _isTapped = YES; [self.nextResponder.nextResponder touchesBegan:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ _isTapped = NO; [self.nextResponder.nextResponder touchesMoved:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ if (_isTapped){ //Functionality } 

Why is touchesMoved called on these devices and how can I solve it?

+5
source share
1 answer

Maybe higher resolution screens are more sensitive to any movement. When you press, you can actually slightly tilt your finger to make it appear small.

Two possible solutions.

  • Check how far the touch is moved in your touchesMoved: method. If this is a really small move, ignore it for _isTapped verification _isTapped .
  • Instead of overriding the touches... methods, use the UITapGestureRecognizer . Let him do all the hard work to determine what is a crane and what is not. This will make your code a lot easier.
+5
source

Source: https://habr.com/ru/post/1258841/


All Articles