It looks like you're new here. If you want to get involved, click one of these buttons!
- (void) drawHighlight{
//Create drawing view
HighlightView *hl = [[HighlightView alloc] initWithFrame:self.view.bounds];
//Add to VC's scrollview
[self.scrollView addSubview:hl];
//Store in a nice array
[self.highlightViews addObject:hl];
//Ensure it's on top
[self.scrollView bringSubviewToFront:hl];
//Finish
[hl release];
}
#import \"HighlightView.h\"
@implementation HighlightView
@synthesize context, canvas, swiped;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@\"%s\", __PRETTY_FUNCTION__);
currentStart = CGPointZero;
self.backgroundColor = [UIColor clearColor];
//Make a canvas to draw on
canvas = [[UIImageView alloc] initWithImage:nil];
canvas.frame = self.frame;
[self addSubview:canvas];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
swiped = NO;
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
//canvas.image = nil;
return;
}
currentEnd = [touch locationInView:self];
currentEnd.y -= 20;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
swiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.frame.size);
[canvas.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), currentEnd.x, currentEnd.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
canvas.image = UIGraphicsGetImageFromCurrentImageContext();
//UIGraphicsEndImageContext();
currentEnd = currentPoint;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
//How do I stop the drawing?
if ([touch tapCount] == 2)
{
// canvas.image = nil;
return;
}
}
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome