Created
August 4, 2014 18:49
-
-
Save dmathewwws/a8971433dcaf014f4aef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LHDFingerpaintView.m | |
// Drawing | |
// | |
// Created by Steven Masuch on 2014-07-31. | |
// Copyright (c) 2014 Lighthouse Labs. All rights reserved. | |
// | |
#import "LHDFingerpaintView.h" | |
@interface LHDTouchPair : NSObject | |
@property (nonatomic) CGPoint touch1Point; | |
@property (nonatomic) CGPoint touch2Point; | |
@end | |
@implementation LHDTouchPair | |
@end | |
@interface LHDFingerpaintView () | |
@property (nonatomic) NSMutableArray * touchPairs; | |
@end | |
@implementation LHDFingerpaintView | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
_touchPairs = [NSMutableArray array]; | |
} | |
return self; | |
} | |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
// We don't need to do anything here | |
} | |
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
// Here's the meat of this | |
for (UITouch *touch in touches) { | |
LHDTouchPair *touchPair = [[LHDTouchPair alloc] init]; | |
touchPair.touch1Point = [touch locationInView:self]; | |
touchPair.touch2Point = [touch previousLocationInView:self]; | |
[self.touchPairs addObject:touchPair]; | |
} | |
[self setNeedsDisplay]; | |
} | |
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
} | |
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
} | |
- (void)drawRect:(CGRect)rect | |
{ | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); | |
CGContextSetLineWidth(context, 5.0); | |
for (LHDTouchPair *pair in self.touchPairs) { | |
CGContextBeginPath(context); | |
CGContextMoveToPoint(context, pair.touch1Point.x, pair.touch1Point.y); | |
CGContextAddLineToPoint(context, pair.touch2Point.x, pair.touch2Point.y); | |
CGContextStrokePath(context); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment