【问题标题】:Is there a way to ignore a uitouch in objective-c?有没有办法忽略objective-c中的uitouch?
【发布时间】:2014-08-21 02:33:16
【问题描述】:

我正在尝试制作这个应用程序:

  1. 用户将手指放在要跟踪的屏幕上。
  2. 第二根手指在第一根手指周围画出第一根手指的轮廓。(本质上只是一个忽略第一根手指在屏幕上的绘图应用程序)

问题:

它创建的不是轮廓,而是星形。似乎正在绘制的线试图连接到两个接触点。

问题:

  1. 有没有办法忽略多点触控应用中的特定触控?
  2. 有没有办法在单点触控应用中取消第一次触控?

我的代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

   touchCount++;
   NSLog(@"Touches Count: %i", touchCount);

    if(touchCount >= 2)
    {
        drawingTouch = [touches anyObject];
        CGPoint p = [drawingTouch locationInView:self];
        [path moveToPoint:p];
        drawingPoints = [[NSMutableArray alloc]init];
    }
    else
    {
        //???
    }


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
   NSArray *allTouches = [touches allObjects];

   if(touchCount >= 2 && [allTouches count]>1)
   {
         UITouch *theTouch = allTouches[1];
         CGPoint p = [theTouch locationInView:self];
         [path addLineToPoint:p]; // (4)
         [self setNeedsDisplay];
         [drawingPoints addObject:[NSValue valueWithCGPoint:p]];
   }


}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self touchesMoved:touches withEvent:event];// This was copied from a tutorial but I will remove it and see what happens. 

}

【问题讨论】:

  • 你不应该自己打电话给[self touchesMoved:touches withEvent:event]

标签: objective-c drawing uibezierpath uitouch


【解决方案1】:

触摸点在内部计算为触摸区域的中心;更具体地说,输出到touchesBegantouchesMovedtouchesEnded 的点略高于中心。轮廓只能是第二根手指触摸的所有点的组合,但它会比第一根手指本身大得多。您所能做的就是在第一个触摸点周围创建一个圆圈,该圆圈与第二根手指的移动平行。

您描述的星状图案表明您没有将正确的触摸点分配给右手手指。尝试使用指向(NSSet *)touches 中的触摸的指针作为NSDictionary 中的键,并收集您放入字典中的NSMutableArray 中的点,每个手指一个。

在随后对touchesBegantouchesMovedtouchesEnded 的调用中,iOS 将对同一手指的后续触摸使用相同的地址。当您跟踪指针时,您就知道哪个触摸事件属于哪个手指。然后您可以决定处理哪些触摸以及忽略哪些触摸,但所有触摸都将在对touchesBegantouchesMovedtouchesEnded 的调用中报告。

【讨论】:

    【解决方案2】:

    您不能在手指周围追踪(如绘制轮廓)。触摸事件代表坐标系中的一个点;它并不代表屏幕上被触摸的所有像素。

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多