I have looked long and hard for a solution to this problem and I don't think there is one. However, on closer inspection of the documentation I think it might be a misunderstanding that begintrackingWithTouch:withEvent:
and continueTrackingWithTouch:withEvent:
are supposed to be called at all...
UIControl
documentation says:
You may want to extend a UIControl
subclass for two basic reasons:
To observe or modify the dispatch of
action messages to targets for
particular events To do this, override
sendAction:to:forEvent:
, evaluate the
passed-in selector, target object, or
“Note” bit mask and proceed as
required.
To provide custom tracking behavior
(for example, to change the highlight
appearance) To do this, override one
or all of the following methods:
beginTrackingWithTouch:withEvent:
,
continueTrackingWithTouch:withEvent:
,
endTrackingWithTouch:withEvent:
.
The critical part of this, which is not very clear in my view, is that it says you may want to extend a UIControl
subclass - NOT you may want to extend UIControl
directly. It's possible that beginTrackingWithTouch:withEvent:
and continuetrackingWithTouch:withEvent:
are not supposed to get called in response to touches and that UIControl
direct subclasses are supposed to call them so that their subclasses can monitor tracking.
So my solution to this is to override touchesBegan:withEvent:
and touchesMoved:withEvent:
and call them from there as follows. Note that multi-touch is not enabled for this control and that I don't care about touches ended and touches canceled events, but if you want to be complete/thorough you should probably implement those too.
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// Get the only touch (multipleTouchEnabled is NO)
UITouch* touch = [touches anyObject];
// Track the touch
[self beginTrackingWithTouch:touch withEvent:event];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
// Get the only touch (multipleTouchEnabled is NO)
UITouch* touch = [touches anyObject];
// Track the touch
[self continueTrackingWithTouch:touch withEvent:event];
}
Note that you should also send any UIControlEvent*
messages that are relevant for your control using sendActionsForControlEvents:
- these may be called from the super methods, I haven't tested it.