Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <code>begintrackingWithTouch:withEvent:</code> and <code>continueTrackingWithTouch:withEvent:</code> are supposed to be called at all...</p> <p><code>UIControl</code> documentation says:</p> <blockquote> <p>You may want to extend a <code>UIControl</code> subclass for two basic reasons:</p> <p>To observe or modify the dispatch of action messages to targets for particular events To do this, override <code>sendAction:to:forEvent:</code>, evaluate the passed-in selector, target object, or “Note” bit mask and proceed as required.</p> <p>To provide custom tracking behavior (for example, to change the highlight appearance) To do this, override one or all of the following methods: <code>beginTrackingWithTouch:withEvent:</code>, <code>continueTrackingWithTouch:withEvent:</code>, <code>endTrackingWithTouch:withEvent:</code>.</p> </blockquote> <p>The critical part of this, which is not very clear in my view, is that it says you may want to extend a <code>UIControl</code> subclass - NOT you may want to extend <code>UIControl</code> directly. It's possible that <code>beginTrackingWithTouch:withEvent:</code> and <code>continuetrackingWithTouch:withEvent:</code> are not supposed to get called in response to touches and that <code>UIControl</code> direct subclasses are supposed to call them so that <em>their</em> subclasses can monitor tracking.</p> <p>So my solution to this is to override <code>touchesBegan:withEvent:</code> and <code>touchesMoved:withEvent:</code> 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.</p> <pre><code>- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [super touchesBegan:touches withEvent: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 { [super touchesMoved:touches withEvent:event]; // Get the only touch (multipleTouchEnabled is NO) UITouch* touch = [touches anyObject]; // Track the touch [self continueTrackingWithTouch:touch withEvent:event]; } </code></pre> <p>Note that you should also send any <code>UIControlEvent*</code> messages that are relevant for your control using <code>sendActionsForControlEvents:</code> - these may be called from the super methods, I haven't tested it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload