Question

I tried to use custom UIControl in my view controller. My custom class which subclasses the UIControl and allocate the instance for my custom control and adding in to my view controller's view by following code

I have implemented following delegates which returns for YES to ensure the continuous touch.

 - (BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
        [super beginTrackingWithTouch:touch withEvent:event];
        return YES;
    }

    - (BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
        [super continueTrackingWithTouch:touch withEvent:event];
        return YES;
    }

    - (void) endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
        [super endTrackingWithTouch:touch withEvent:event];
    }

    - (void)cancelTrackingWithEvent:(UIEvent *)event
    {
        NSLog(@"Touch cancelled");
    }

But - (void)cancelTrackingWithEvent:(UIEvent *)event get called when I am tracking. After that I should have to taken up my finger and drag again. then only I receive begin and continue tracking delegates

Was it helpful?

Solution

According to your question, While tracking,cancelTrackingWithEvent: get called. Right. Check your view or superview with Gesture call backs. If You've added pan Gesture, This type of problem will rise. That is your control touch will begin and get tracked upto this tracking change to panning.

To solve this issue, set tag to your view and cancel gesture call as below.

During your view creation

yourView.tag = CANCELVIEWTAG;

Cancel gesture if touch happen in your view.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    if (touch.view.tag == CANCELVIEWTAG) {
        return NO;
    }
    return YES;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top