【问题标题】:ContinueTrackingWithTouch doesn't get called continuouslyContinueTrackingWithTouch 不会被连续调用
【发布时间】:2014-01-22 12:02:10
【问题描述】:

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

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

当我在视图内部触摸和跟踪时,continueTrackingWithTouchget 会连续调用,但有时即使我在跟踪它也不会被调用...

提前谢谢...

【问题讨论】:

  • 试试这个 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
  • - (void)cancelTrackingWithEvent:(UIEvent *)event;之后调用此方法,只有 continueTrackingWithTouch 不会被调用
  • 请尝试我给出的答案,我将此代码用于签名功能。此代码将有助于持续跟踪触摸

标签: ios uicontrol


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    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;
    }
    }
    

    【讨论】:

    • touchesMoved 在某个时间点不会被调用。这个方法被称为 cancelTrackingWithEvent 我认为这是没有调用 continueTrackingWithTouch 的原因
    • 我可以知道您使用触摸方法的什么功能?以上 2 种方法足以跟踪用户触摸。如果你使用 cancelTrackingWithEvent 用户不应该停止触摸屏,直到他的工作完成
    • 问题不是我们使用的是哪个委托方法,而是调用了cancelTrackingWithEvent,所以只有touchesMoved不会被调用
    猜你喜欢
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 2019-08-08
    相关资源
    最近更新 更多