2
votes

I'm creating a custom control* by subclassing UIControl and overriding the following methods:

  • - beginTrackingWithTouch:withEvent:
  • - continueTrackingWithTouch:withEvent:
  • - endTrackingWithTouch:withEvent:
  • - cancelTrackingWithEvent:

This control will support multitouch interaction. Specifically, one or two fingers may touch down, drag for some duration, and then touch up, all independently.

My issue comes at the end of these multitouch events, in endTrackingWithTouch:withEvent:. The system calls this method on my control exactly once per multitouch sequence, and it is called on the first touch up that occurs. This means that the second touch, which could still be dragging, will no longer be tracked.

This sequence of actions serves as an example for this phenomenon:

  1. Finger A touches down. beginTracking is called.
  2. Finger A drags around. continueTracking is called repeatedly to update my control.
  3. Finger B touches down. beginTracking is called.
  4. Fingers A and B drag around. continueTracking is called repeatedly to update my control.
  5. Finger B touches up. endTracking is called.
  6. Finger A drags around. No methods are called.
  7. Finger A touches up. No methods are called.

The issue lies in the final three steps in this sequence. The documentation for UIControl says the following of endTrackingWithTouch:withEvent::

Sent to the control when the last touch for the given event completely ends, telling it to stop tracking.

Yet it seems to me that after finger B touches up in step 5, above, the last touch for the given event has not yet completely ended. That last touch is finger A!


*A range slider, if you must ask. But there are already plenty of open source range sliders, you say. Yes, true, but this one will support multitouch and Auto Layout.

1

1 Answers

1
votes

I had the same issue in custom control with multitouch.
Because UIControl is subclass of UIView that inherits from UIResponder, so feel free to use:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

methods.

These methods work fine in UIControl subclass.