Linha Stretchy UIBezierPath?
Eu quero desenhar uma linha reta com o dedo que automaticamente dimensiona com base em quão longe eu estou do ponto de origem.
Então, se eu tocar a tela no meio e deslizar o dedo para fora, uma linha parecerá "esticar" e girar em torno do ponto de orgina quando meu dedo se mover na tela. Quando eu levanto meu dedo. O ponto de destino deve finalizar e criar uma linha. Eu posso arrastar o dedo pela tela e desenhar na tela, mas não é isso que estou querendo fazer.
Eu pensei que o UIBeizerPath moveToPoint iria ajudar, mas isso só estraga as coisas.
O que estou fazendo de errado?
- (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];
}