I'm trying to add line between two points based on user touch(start point will be user's first touch & end point will be user's second touch on the view).I was able to draw it using below code.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2)
{
NSLog(@"touch count 2");
return;
}
if(isOdd)//View already has user's start point
{
nextPoint = [touch locationInView:self.view];
point2 = nextPoint;
//nextPoint.y -= 20;
[self drawLineFromPoint:currentPoint toPoint:nextPoint];
currentPoint = nextPoint;
NSLog(@"x:%f,y:%f",currentPoint.x,currentPoint.y);
isOdd = YES;
}
else
{
currentPoint = [touch locationInView:self.view];
point1 = currentPoint;
NSLog(@"x:%f,y:%f",currentPoint.x,currentPoint.y);
isOdd = YES;
}
}
-(void)drawLineFromPoint:(CGPoint)start toPoint:(CGPoint)end
{
UIBezierPath *path = [UIBezierPath new];
[path moveToPoint:start];
[path addLineToPoint:end];
CAShapeLayer *shapeLayer = [CAShapeLayer new];
shapeLayer.path = path.CGPath;
shapeLayer.strokeColor = [UIColor greenColor].CGColor;
shapeLayer.lineWidth = 3.0;
[self.myView.layer addSublayer:shapeLayer];
}
Now my question is, Is it possible to curve that line when user tries to drag/move that line using finger?