0
我是Objective-C編程的新手。當我畫新線時,舊線消失
我的問題是關於用touchesMoved繪製線條。
我的代碼是這樣的:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, YES);
CGContextSetLineWidth(context, 7.0f);
CGContextSetRGBStrokeColor(context, 0.7, 0.7, 0.7, 1.0);
CGContextMoveToPoint(context, self.touchedPoint2.x, self.touchedPoint2.y);
CGContextAddLineToPoint(context, self.touchedPoint.x, self.touchedPoint.y);
CGContextDrawPath(context,kCGPathFillStroke);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
self.touchedPoint = [[touches anyObject] locationInView:self];
[self setNeedsDisplay];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.touchedPoint2 = [[touches anyObject] locationInView:self];
}