ContinueTrackingWithTouch不会被连续调用

时间:2014-01-22 12:02:11

标签: ios uicontrol

我正在创建UIControl的子类并添加到我的视图控制器的视图

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

当我触摸并跟踪视图内部时,continueTrackingWithTouch会被连续调用,但有些情况下即使我正在跟踪它也不会被调用...

提前致谢...

2 个答案:

答案 0 :(得分:1)

我知道这已经过时了,但我遇到了同样的问题,检查你的一个超级视图是否有手势识别器,并在需要使用UIControl时停用它们。

我实际上已经更改了UIControl的超级视图以避免这种冲突。

答案 1 :(得分:0)

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