【发布时间】:2013-03-08 14:18:29
【问题描述】:
我的 UIVIew 中有两个方形图像。一旦我将手指从一个图像拖动到另一个图像,我想在它们之间画一条直线。
我已经处理了touchesMoved 方法来检查我的 touchLocation 何时到达任一图像的框架。所以我已经处理了 when 开始绘制的逻辑部分以及 在哪两点之间。
我只是不知道如何使用(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吗? -
drawRect 没有被调用..no我没有调用-setneedsDisplay。我必须在哪里调用它?