0

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?

twernt
  • 20,271
  • 5
  • 32
  • 41
aryaxt
  • 76,198
  • 92
  • 293
  • 442

2 Answers2

1

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
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • But I want to cancel the touch event when the touches are out of my UIView frame, and it doesn't do that. That's how most UI elements work and I'm trying to follow the same pattern – aryaxt Aug 01 '11 at 02:57
  • @Aryaxt I see what you mean, I don't know if that is possible. – Oscar Gomez Aug 01 '11 at 03:01
  • I ended up using a BOOL flag that i set to NO when touches begin and i set to YES when touches move out of the view bounds. – aryaxt Aug 01 '11 at 03:24
0

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

touchesCancelled:withEvent:.

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55