Stretchy UIBezierPath Linie?

Ich möchte mit meinem Finger eine gerade Linie zeichnen, deren Größe automatisch davon abhängt, wie weit ich vom Ausgangspunkt entfernt bin.

Wenn ich also den Bildschirm in der Mitte berühre und meinen Finger herausschiebe, wird eine Linie angezeigt, die sich „streckt“ und um den Ursprungspunkt schwenkt, während sich mein Finger auf dem Bildschirm bewegt. WENN ich meinen Finger hebe. Der Zielpunkt sollte finalisiert und eine Linie erstellt werden. Ich kann meinen Finger über den Bildschirm ziehen und auf dem Bildschirm zeichnen, aber das ist nicht das, was ich tun möchte.

Ich dachte, UIBeizerPath moveToPoint würde helfen, aber es bringt die Dinge nur durcheinander.

Was mache ich falsch?

- (id)initWithFrame:(CGRect)frame
{
     //default line properties
    myPath=[[UIBezierPath alloc]init];
    myPath.lineCapStyle=kCGLineCapRound;
    myPath.miterLimit=0;
    myPath.lineWidth=lineWidth;
    brushPattern=[UIColor blackColor];
 }



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint curPoint = [[touches anyObject] locationInView:self];

    lastPoint = curPoint;

    [myPath moveToPoint:lastPoint];
    [pathArray addObject:myPath];
    [self setNeedsDisplay];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    CGPoint curPoint = [[touches anyObject] locationInView:self];

    myPath.lineWidth=lineWidth;
    brushPattern=[UIColor redColor]; //red to show it hasn't been added yet.
    [myPath moveToPoint:tempPoint];
    [self setNeedsDisplay];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint curPoint = [[touches anyObject] locationInView:self];

    myPath.lineWidth=lineWidth;

    brushPattern=[UIColor blackColor]; //finalize the line with black color
    [myPath addLineToPoint:curPoint];
    [self setNeedsDisplay];
}

Antworten auf die Frage(2)

Ihre Antwort auf die Frage