Permalink
Browse files

One finger erases when close enough to another, else it draws

  • Loading branch information...
paulaj committed Jun 3, 2010
1 parent d8a9121 commit 7b4b0333c80fe874846cb84f65e6f31d5c0b6bc3
Showing with 20 additions and 7 deletions.
  1. +1 −0 Classes/WhiteboardView.h
  2. +19 −7 Classes/WhiteboardView.m
View
@@ -15,6 +15,7 @@
NSMutableArray *myArray;
Boolean isErasing;
UIColor *myColor;
+ CGFloat myDistance;
}
//@property (nonatomic, assign) CGPoint lastLocation;
View
@@ -7,7 +7,7 @@
//
#import "WhiteboardView.h"
-
+#import <math.h>
@implementation WhiteboardView
//@synthesize lastLocation;
@@ -19,6 +19,8 @@ - (id)initWithFrame:(CGRect)frame {
myArray = [[NSMutableArray array] retain];
isErasing=true;
myColor= [UIColor blueColor];
+ myDistance=0.0;
+
}
return self;
}
@@ -73,20 +75,30 @@ - (void)drawRect:(CGRect)rect {
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
- if ([[event allTouches] count]==1){
- isErasing=false;
+ //Stores current location of touch in our instance variable lastLocation
+ lastLocation = [touch locationInView:self];
+ if ([[event allTouches] count]==2){
+ CGPoint point1=[[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
+ CGPoint point2=[[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
+ myDistance = sqrt(pow(((point2.x) - (point1.x)), 2) + pow(((point2.y) - (point1.y)), 2));
+ if (myDistance<=300){
+ isErasing=true;
+ //lastLocation= MakeCGPoint(
+ }
+ else{
+ isErasing=false;
+ }
}
- if ([[event allTouches] count]==2) {
- isErasing=true;
+ else{
+ isErasing=false;
}
if (isErasing){
myColor=[UIColor blackColor];
}
else {
myColor=[UIColor blueColor];
}
- //Stores current location of touch in our instance variable lastLocation
- lastLocation = [touch locationInView:self];
+
//Creates an Array and adds it into our initial Array, then adds a color to it
[myArray addObject:[[NSMutableArray alloc] initWithCapacity:4]];
[[myArray lastObject] addObject: myColor];

0 comments on commit 7b4b033

Please sign in to comment.