繪製兩點之間的直線我有我的UIView兩個方形的圖像。一旦我將手指從一個圖像拖到另一個圖像上,我想在它們之間繪製一條直線。通過拖動IOS
我處理了touchesMoved
方法來檢查我的touchLocation何時到達任一圖像的框架。所以我在的開始繪製和兩個點之間處理邏輯部分。
我只是無法弄清楚如何,使用(void)drawRect:(CGRect)rect
做。首先,我在drawRect中添加了一個NSlog,並且我編寫了代碼在兩行之間繪製一條線,即使這沒有發生。
我檢查這個question too,但我想繼續拖累和繪製多個點之間的線路。
- (void)drawRect:(CGRect)rect
{
NSLog(@"Draw Rect Entered");
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor]CGColor]);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 20, 20);
CGContextStrokePath(context);
}
是'-drawRect:'絕對被稱爲 - 你叫'地方-setNeedsDisplay'? 。 – 2013-03-08 14:25:14
drawRect中沒有得到called..no我「米不是要求-setneedsDisplay我在哪裏都叫它 – 2013-03-08 14:26:51