jailani
jailani

Reputation: 2270

ContinueTrackingWithTouch doesn't get called continuously

I am creating a subclass of UIControl and adding to my view controller's view

- (BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (void) endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;

when I touch and track inside of view the continueTrackingWithTouchget called continuously but some point it doesn't get called even If I am tracking...

Thanks in advance...

Upvotes: 1

Views: 761

Answers (2)

ZiggyST
ZiggyST

Reputation: 587

I know this is old, but I had the same problem, check if one of your superviews has gesture recogniser, and deactivate them when you need to user the UIControl.

I actually ended changed the superview of the UIControl to avoid this conflicts.

Upvotes: 1

Charan Giri
Charan Giri

Reputation: 1097

Try This the below code is for signature feature this will help you to see how to track touch continuously 

CGPoint lastPoint;
BOOL mouseSwiped;
int mouseMoved;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
/*  The below statements will help to get the exact point user touches with out this it will take ZERO yaxis  */
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:signatureImageView]; // replace signatureImageView with your view
lastPoint.y -= 20;     
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;

UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:signatureImageView];// replace signatureImageView with your view
currentPoint.y -= 20;

UIGraphicsBeginImageContext(signatureImageView.frame.size);
[signatureImageView.image drawInRect:CGRectMake(0, 0, signatureImageView.frame.size.width, signatureImageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapButt);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
signatureImageView.image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

lastPoint = currentPoint;

mouseMoved++;
if (mouseMoved == 20) {
    mouseMoved = 0;
}
}

Upvotes: 0

Related Questions