zeichnen Sie eine Linie in UIImageView problem

In meiner Anwendung kann ich zeichnen Sie eine Linie in eine UIImageView, die von dem code unten und ich möchte Neuzeichnen der Linie sogar noch länger, wenn ich die Funktion aufrufen,jedoch die Ausgabe herauskommen, ist nicht, wie erwartet,wird es nur eine neue Linie zeichnen und entfernen Sie die alte ein,wird die Länge gleich bleiben jus die y-position ist anders,ich weiß nicht, welche Zeile in meinem code falsch ist oder ich nicht verstehen, die CGContext Klasse in der richtigen Art und Weise,bitte Hilfe ich habe meinen Kopf kratzen alle Tage und kann nicht herausfinden, das 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 versuchte Ihren code, und es scheint gut zu funktionieren.
  • könnten Sie bitte poste deinen kompletten code, wo sind die currentPoint und lastPoint; deklariert
InformationsquelleAutor | 2009-03-25
Schreibe einen Kommentar