Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 0.0)
- CGPoint previousPoint;
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- previousPoint = [touch locationInView:self];
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [touches anyObject];
- currentPoint = [touch locationInView:self];
- UIGraphicsBeginImageContext(self.frame.size);
- //This may not be necessary if you are just erasing, in my case I am
- //adding lines repeatedly to an image so you may want to experiment with moving
- //this to touchesBegan or something. Which of course would also require the begin
- //graphics context etc.
- [scratchImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- CGContextSaveGState(UIGraphicsGetCurrentContext());
- CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.25, 0.25, 0.25, 1.0);
- CGMutablePathRef path = CGPathCreateMutable();
- CGPathMoveToPoint(path, nil, previousPoint.x, previousPoint.y);
- CGPathAddLineToPoint(path, nil, currentPoint.x, currentPoint.y);
- CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
- CGContextAddPath(UIGraphicsGetCurrentContext(), path);
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- scratchImage.image = UIGraphicsGetImageFromCurrentImageContext();
- CGContextRestoreGState(UIGraphicsGetCurrentContext());
- UIGraphicsEndImageContext();
- previousPoint = currentPoint;
- }
Add Comment
Please, Sign In to add comment