Línea elástica UIBezierPath?
Quiero dibujar una línea recta con mi dedo que se ajuste automáticamente según la distancia a la que estoy del punto de origen.
Entonces, si toco la pantalla en el medio y deslizo el dedo, una línea parece "estirarse" y girar alrededor del punto de origen a medida que mi dedo se mueve en la pantalla. Cuando levanto mi dedo. El Punto de Destino debe finalizar y crear una línea. Puedo arrastrar mi dedo por la pantalla y "Dibujar" en la pantalla, pero eso no es lo que quiero hacer.
Pensé que UIBeizerPath moveToPoint ayudaría, pero simplemente desordena las cosas.
¿Qué estoy haciendo mal?
- (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];
}