jailani
jailani

Reputation: 2270

cancelTrackingWithEvent get called even touch delegate returns YES

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

Upvotes: 1

Views: 726

Answers (1)

Mani
Mani

Reputation: 17585

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;
}

Upvotes: 1

Related Questions