Skip to content

Commit

Permalink
added methods for 1 and 2 touches
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Mar 22, 2012
1 parent b16705d commit 3736bd2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
3 changes: 3 additions & 0 deletions MovingShapes/ShapeView.h
Expand Up @@ -11,6 +11,9 @@

@protocol ShapeViewDelegate <NSObject>

@optional
- (void)shapeViewDidTouchWithOnePoint:(HKPoint*) point;
- (void)shapeViewDidTouchWithTwoPoints:(NSArray *)points;
- (void)shapeViewDidTouchWithThreePoints:(NSArray *)points;

@end
Expand Down
40 changes: 18 additions & 22 deletions MovingShapes/ShapeView.m
Expand Up @@ -32,28 +32,24 @@ - (void)threeTouched:(UITapGestureRecognizer *)sender {
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
NSMutableArray *points = [NSMutableArray arrayWithCapacity: allTouches.count];
if (allTouches.count == 3){
[allTouches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = (UITouch *) obj;
HKPoint *point = [[HKPoint alloc] initWithCGPoint: [touch locationInView:self]];
[points addObject: point];
}];

[delegate shapeViewDidTouchWithThreePoints: points];
}
// [touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
// // Get a single touch and it's location
// UITouch *touch = obj;
// CGPoint touchPoint = [touch locationInView:self.view];
//
// // Draw a red circle where the touch occurred
// UIView *touchView = [[UIView alloc] init];
// [touchView setBackgroundColor:[UIColor redColor]];
// touchView.frame = CGRectMake(touchPoint.x, touchPoint.y, 30, 30);
// touchView.layer.cornerRadius = 15;
// [self.view addSubview:touchView];
// [touchView release];
// }];

[allTouches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = (UITouch *) obj;
HKPoint *point = [[HKPoint alloc] initWithCGPoint: [touch locationInView:self]];
[points addObject: point];
}];

switch (allTouches.count) {
case 1:
[delegate shapeViewDidTouchWithOnePoint: [points objectAtIndex: 0]];
break;
case 2:
[delegate shapeViewDidTouchWithTwoPoints: points];
break;
case 3:
[delegate shapeViewDidTouchWithThreePoints: points];
break;
}
}

/*
Expand Down
10 changes: 9 additions & 1 deletion MovingShapes/ViewController.m
Expand Up @@ -18,8 +18,16 @@ - (void)didReceiveMemoryWarning
// Release any cached data, images, etc that aren't in use.
}

- (void)shapeViewDidTouchWithOnePoint:(HKPoint *)point {
NSLog(@"1 point: %@", point);
}

- (void)shapeViewDidTouchWithTwoPoints:(NSArray *)points {
NSLog(@"2 points: %@", points);
}

- (void)shapeViewDidTouchWithThreePoints:(NSArray *)points {
NSLog(@"points %@", points);
NSLog(@"3 points: %@", points);
}

#pragma mark - View lifecycle
Expand Down

0 comments on commit 3736bd2

Please sign in to comment.