You can store the touched locations in two different CGPoint
with the help of the touchedEnded
method (documentation).
Then, when you have your two points, you can add a new UIView as subview which is aware of the two CGPoint
and will draw a line in its drawRect
method. Or do it in the current view, by calling [view setNeedsDisplay]
to trigger its own drawRect
method.
If you don't know how to draw a simple line with CoreGraphics, here is the beginning :
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor]CGColor]);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, startPoint.x, startPoint.y);
CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…