iPhone - Detecting touches and canceling them?

1.9k views Asked by At

I am dtecting touches on my UIView. Is some situations I want to be abel to cancel touches so that touchesEnded won't get called. But doesn't matter what touchesEnded will always get called?

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
   if (SOMETHING_SPECIAL)
   {
      [super touchesCancelled:touches withEvent:event];
   }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
   //I don't want it to get here if touches were canceled how can i do this?
}

- In my touchesEnded how can I determine whether touches were canceled or not?

2

There are 2 answers

3
Oscar Gomez On BEST ANSWER

TouchesEnded will always get called wherever your touches where canceled or not, so I would suggest instead having that exact:

   if (SOMETHING_SPECIAL)
   {

   }

In your:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
0
Ilanchezhian On

To get the touchesCancelled event, implement this method from UIResponder.

touchesCancelled:withEvent:.