2012-06-15 68 views

回答

5

您可以用两种不同的CGPointtouchedEnded法(documentation)的帮助下存储触摸位置。

然后,当你有两点时,你可以添加一个新的UIView作为子视图,它知道两个CGPoint,并将在其drawRect方法中画一条线。或者在当前视图中通过调用[view setNeedsDisplay]来触发其自己的drawRect方法。


如果你不知道如何来绘制一个CoreGraphics的简单的线条,这里是开始:

- (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); 
} 
0

你应该为此使用UIBezierPath。由此可以得出线曲线,如果你给点正式文件是here

检查here以及

相关问题