私のアプリでは、ユーザーが地図をタッチして移動しているときに、2本の線を描きたいと思っています。これどうやってするの。以下のコードを使用して、1本の線を描画しています。 コード:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:drawImage];
currentPoint.y -= 20;
mapView.scrollEnabled = NO;
lastpinpoint1.x = 170.000000;
lastpinpoint1.y = 327.000000;
UIGraphicsBeginImageContext(drawImage.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[imgMap drawInRect:CGRectMake(0, 0, drawImage.frame.size.width,drawImage.frame.size.height)];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 2.0);
// CGContextSetRGBStrokeColor(ctx, 0.0, 0.5, 0.6, 1.0);
CGContextSetStrokeColorWithColor(ctx, [[UIColor redColor] CGColor]);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, lastpinpoint.x, lastpinpoint.y);
CGContextMoveToPoint(ctx, lastpinpoint1.x, lastpinpoint1.y);
CGContextAddLineToPoint(ctx, currentPoint.x, currentPoint.y);
CGContextStrokePath(ctx);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
この上記のコードでは、このCGContextMoveToPoint(ctx、lastpinpoint1.x、lastpinpoint1.y);がありません。この線は一本の線を引くためのものです。しかし、私はこのCGContextMoveToPoint(ctx、lastpinpoint1.x、lastpinpoint1.y);を追加しました。2番目の線を引くための線。さて、このコードで何が間違っていたのか。私を助けてください。問題は、地図上で指を動かしているときに、別のポイントから1つの現在のポイントに2本の線を描きたいということです。よろしくお願いします。