As far as I know, you can also use Core Graphics to draw a line, and from your question you do not need to create views for each individual line, instead, your single graphic view context will be a drawing sheet for all the drawing, and you are almost closer to the solution. Just using the touch coordinate, you can draw lines on the screen.
CGPoint previousPoint; // This must have a global scope, it will be used in all touch events
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
UITouch * touch = [touches anyObject];
previousPoint = [touch locationInView: self]; // take the starting touch point;
}
- (void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
{
CGPoint currentPoint;
UITouch * touch = [touches anyObject];
currentPoint = [touch locationInView: self];
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextSetLineWidth (context, 2.0);
CGContextMoveToPoint (context, previousPoint.x, previousPoint.y);
CGContextAddLineToPoint (context, currentPoint.x, currentPoint.y);
CGContextStrokePath (bluecontext);
}
Hope this helps you, Let me know any problem ....
source share