continueTrackingWithTouch: withEvent: not being called continuously.

Posted by Steven Noyes on Stack Overflow See other posts from Stack Overflow or by Steven Noyes
Published on 2010-03-09T02:39:37Z Indexed on 2010/03/09 2:51 UTC
Read the original article Hit count: 358

Filed under:
|

I have a very simply subclass of UIButton that will fire off a custom event when the button has been held for 2 seconds. To accomplish this, I overrode:

//
// Mouse tracking
//
- (BOOL)beginTrackingWithTouch:(UITouch *)touch 
                     withEvent:(UIEvent *)event
{
    [super beginTrackingWithTouch:touch withEvent:event];
    [self setTimeButtonPressed:[NSDate date]];

    return (YES);
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [super continueTrackingWithTouch:touch withEvent:event];
    if ([[self timeButtonPressed] timeIntervalSinceNow] > 2.0)
    {
        //
        // disable the button.  This will eventually fire the event
        // but this is just stubbed to act as a break point area.
        //
        [self setEnabled:NO];
        [self setSelected:NO];
    }

    return (YES);
}

My problem is (this is in the simulator, can't do on device work quite yet) "continueTrackingWithTouch: withEvent:" is not being called unless the mouse is actually moved. It does not take much motion, but it does take some motion.

By returning "YES" in both of these, I should be setup to receive continuous events. Is this an oddity of the simulator or am I doing something wrong?

NOTE: userInteractionEnabled is set to YES.

NOTE2: I could setup a timer in beginTrackingWithTouch: withEvent: but that seems like more effort for something that should be simple.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch