i'm trying to produce code that will allow for tracking of touches, and have the touches' coordinates displayed in the appropriate label (touchLabel1, touchLabel2, touchLabel3) according to the touches order.
one finger touches or moves around the screen and displays this first touch's coordinates in touchLabel1. if another finger touchs the screen, it's coordinates will be displayed in touchLabel2. if a third finger touches the screen, it's coordinates will be displayed in touchLabel3.
now for the part i'm having difficulty with: if all 3 fingers are touching the screen and displaying their own coordinates in the appropriate label, i want to be able to have the 2nd finger removed, set it's label back to "Touch 2: {0, 0}" while the first and third fingers continue to track their positions in their appropriate labels.
i have no idea how to write the touchesEnded: method for what i'm trying to accomplish.
one finger touches or moves around the screen and displays this first touch's coordinates in touchLabel1. if another finger touchs the screen, it's coordinates will be displayed in touchLabel2. if a third finger touches the screen, it's coordinates will be displayed in touchLabel3.
now for the part i'm having difficulty with: if all 3 fingers are touching the screen and displaying their own coordinates in the appropriate label, i want to be able to have the 2nd finger removed, set it's label back to "Touch 2: {0, 0}" while the first and third fingers continue to track their positions in their appropriate labels.
i have no idea how to write the touchesEnded: method for what i'm trying to accomplish.
Code:
- (void)viewDidLoad
{
labelsArray = [[NSArray alloc] initWithObjects:touchLabe1, touchLabe2, touchLabe3, nil];
touchesArray = [[NSMutableArray alloc] initWithCapacity:3];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches)
[touchesArray addObject:touch];
for (NSUInteger i = 0; i < 3; i++)
{
UILabel *aLabel = [labelsArray objectAtIndex:i];
if (i < [touchesArray count])
{
UITouch *touch = [touchesArray objectAtIndex:i];
NSString *point = NSStringFromCGPoint([touch locationInView:self.view]);
aLabel.text = [NSString stringWithFormat:@"Title %i:\n%@", i+1, point];
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (NSUInteger i = 0; i < 3; i++)
{
UILabel *aLabel = [labelsArray objectAtIndex:i];
if (i < [touchesArray count])
{
UITouch *touch = [touchesArray objectAtIndex:i];
NSString *point = NSStringFromCGPoint([touch locationInView:self.view]);
aLabel.text = [NSString stringWithFormat:@"Title %i:\n%@", i+1, point];
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//??
}