so I’m doing this painting application in iOS, and I have a question…
Right now I draw a circle where the user taps… But here’s the problem. When the user taps again, the first circle is moved to the new place. What I want to do is draw a new circle at that position, not move the old one.
I’m using some standard code that is being used in many examples around the net…
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *theTouch = [touches anyObject];
startPoint = [theTouch locationInView:self];
startPoint.x -= 20;
startPoint.y -= 20;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect rectangle = CGRectMake(startPoint.x,startPoint.y,25,25);
CGContextAddEllipseInRect(context, rectangle);
CGContextFillEllipseInRect(context, rectangle);
CGContextStrokePath(context);
}
I know this is probably a pretty noob-ish question 🙂
Also, if anyone could point in the direction of a tutorial or something explaining how to save my image afterwards, that would be really helpful as well…
You will need to track the history of all tap locations and draw a circle at each of those locations in your drawRect method.
For saving as an image you will need to draw to a bitmap context, have a look at Apple’s Quartz 2D Programing Guide for examples of how to do it.