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

1

8

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?

Windward answered 26/10, 2016 at 16:19 Comment(0)
S
7

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.
Substantialism answered 26/10, 2016 at 16:27 Comment(1)
I carefully checked if i am not moving my touch. in older devices no issue but here there is that extra delegate. TapRecognizer will probably solve this problem but any thoughts if this could be solved using touch delegates?Windward

© 2022 - 2024 — McMap. All rights reserved.