3

I am trying to make this app:

  1. User places finger on screen to be traced.
  2. A second finger traces around the first finger and an outline of the first finger should be drawn.(essentially just a drawing app that ignores the first finger being held on the screen)

Problem:

Instead of an outline it creates a star like shape. It seems that the line being drawn tries to connect to both touch points.

Question:

  1. Is there a way to ignore a specific touch in a multi touch app?
  2. Is there way to cancel the first touch in a single touch app?

My Code:

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

}
kaya3
  • 47,440
  • 4
  • 68
  • 97
kkimble006
  • 31
  • 3

2 Answers2

2

Touch points are internally calculated as the center of the touched area; more specifically, the point output to touchesBegan, touchesMoved and touchesEnded is slightly above the center. An outline could only be the combination of all points touched by the second finger, but it would be significantly larger than the first finger by itself. All you can do is to create a circle around the first touch point which is drawn in parallel to the movement of the second finger.

The star like pattern you describe indicates that you do not assign the right touch points to the right fingers. Try to use the pointer to the touches in the (NSSet *)touches as keys in a NSDictionary and collect the points in a NSMutableArray which you put in the dictionary, one for each finger.

In subsequent calls to touchesBegan, touchesMoved and touchesEnded iOS will use the same address for subsequent touches of the same finger. When you track the pointer, you know which touch event belongs to which finger. Then you can decide which touch to process and which to ignore, but all touches will be reported in those calls to touchesBegan, touchesMoved and touchesEnded.

Peter Kämpf
  • 694
  • 11
  • 21
1

You can not trace around the finger (as in drawing outlines). The touch event represents a single point in the coordinate system; it does not represent all of the pixels on screen which are being touched.

Pétur Ingi Egilsson
  • 4,368
  • 5
  • 44
  • 72