有没有办法忽略objective-c中的uitouch?

时间:2014-08-21 02:33:17

标签: objective-c drawing ignore uibezierpath uitouch

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

  1. 用户将手指放在要跟踪的屏幕上。
  2. 第二根手指围绕第一根手指划痕,应绘制第一根手指的轮廓。(基本上只是一个忽略第一根手指放在屏幕上的绘图应用程序)
  3. 问题:

    而不是轮廓,它创造了一个像形状的星形。似乎被绘制的线试图连接到两个触点。

    问题:

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

      - (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. 
      
      }
      

2 个答案:

答案 0 :(得分:2)

触摸点在内部计算为触摸区域的中心;更具体地说,touchesBegantouchesMovedtouchesEnded的点数略高于中心。轮廓只能是第二个手指触摸的所有点的组合,但它本身会明显大于第一个手指。您所能做的就是围绕第一个触摸点创建一个圆圈,该圆圈与第二个手指的运动平行绘制。

您描述的星形模式表示您没有为右手指指定正确的触摸点。尝试使用指向(NSSet *)touches中的触摸的指针作为NSDictionary中的键,并收集放在词典中的NSMutableArray中的点,每个手指一个。

在对touchesBegan的后续通话中,touchesMovedtouchesEnded iOS将使用相同的地址进行同一手指的后续触摸。跟踪指针时,您知道哪个触摸事件属于哪个手指。然后,您可以决定要处理的触摸和要忽略的触摸,但所有触摸都会在对touchesBegantouchesMovedtouchesEnded的调用中报告。

答案 1 :(得分:1)

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

相关问题