Drawing with Quartz2D several 'Images' Array problem?
I am trying to make a simple drawing app atm to learn. As far I got this:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.0, 0.0, 0.0, 1.0};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGPoint firstPoint = [[self.array objectAtIndex: 0] CGPointValue];
CGContextMoveToPoint(context, firstPoint.x, firstPoint开发者_StackOverflow中文版.y);
for (int i = 0; i < [self.array count]; i++) {
CGPoint nextPoint = [[self.array objectAtIndex:i] CGPointValue];
CGContextAddLineToPoint(context, nextPoint.x, nextPoint.y);
}
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
}
Everything works so far, it's drawing where you touch and adding up the coordinates in an Array. If you stop touching and touch at another point it connects the paths you drew before. Which I actually don't want. So I was thinking to create a new array after the touch ended. Am I completely wrong or is that the right direction of doing things? Sometimes I am missing the logic to program, but hey I am still learning!
Thanks in advance!
If you want to collect the touches where you draw things in an array, and you also want to be able to draw separate curves, then you should create a new array at each touchesBegan
. You can do that also in touchesEnd, it is not greatly different. If you really need to store the touches coordinates in an array, I am not sure, it depends on your overall functionality...
精彩评论