In meiner Anwendung kann ich eine Linie in einer UIImageView durch den folgenden Code zeichnen, und ich möchte die Linie noch länger zeichnen, wenn ich die Funktion aufrufen, aber die Ausgabe kommt nicht wie erwartet, es wird nur eine neue Zeile zeichnen und entfernen Sie die alte, die Länge bleibt die gleiche, die y Position anders, ich weiß nicht, welche Zeile meines Codes falsch ist oder ich verstehe nicht die CGContext-Klasse in der richtigen Weise, bitte helfen, ich habe kratzen meinem Kopf alle Tage und können Sie sicher nicht das ProblemZeichnen Sie eine Linie in UIImageView Problem
- (void) drawLine {
lastPoint = currentPoint;
lastPoint.y -= 40;
//drawImage is a UIImageView declared at header
UIGraphicsBeginImageContext(drawImage.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
//sets the style for the endpoints of lines drawn in a graphics context
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineCap(ctx, kCGLineCapButt);
//sets the line width for a graphic context
CGContextSetLineWidth(ctx,2.0);
//set the line colour
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
//creates a new empty path in a graphics context
CGContextBeginPath(ctx);
//begin a new path at the point you specify
CGContextMoveToPoint(ctx, currentPoint.x, currentPoint.y);
//Appends a straight line segment from the current point to the provided point
CGContextAddLineToPoint(ctx, currentPoint.x,lastPoint.y);
//paints a line along the current path
CGContextStrokePath(ctx);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
currentPoint = lastPoint;
}
ich Ihren Code versucht, und es scheint gut zu funktionieren. –
könnten Sie bitte Ihren vollständigen Code posten wo sind der currentPoint und lastPoint; erklärt –