Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

touchesMoved being called on single Tap with iPhone 6s and onwards

I have a custom UIButton and I have implemented touches delegates in custom button class.

Every thing is working fine up until iPhone 6 Plus. All of the devices above it like iPhone 6s and 7 are creating a problem.

When I single tap a button touchesBegan is called as expected but the touchesMoved is also being called and it 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 those devices and how can I solve it?

like image 865
Hassy Avatar asked Oct 26 '16 16:10

Hassy


Video Answer


1 Answers

Could be that the higher resolution screens are more sensitive to any movement. When you are tapping, you may actually be rolling your finger just enough to make it seem like a small move.

Two possible solutions.

  1. Check how far the touch has moved in your touchesMoved: method. If it's a really small move, ignore it for the purposes of your _isTapped check.
  2. Instead of overriding the touches... methods, use a UITapGestureRecognizer. Let it do all of the hard work of determine what is a tap and what isn't. It will make your code much simpler.
like image 142
rmaddy Avatar answered Sep 26 '22 05:09

rmaddy