After drawing lines and circles from bezier path objects i want to now move these objects across the screen. First as i touch on the path object it should get selected which i have done using containsPoint: method.
Now i want that this selected object should get move as i drag my fingure. I am wondering how can i move a stroked bezierpath object to a new location ?
here is my code in touches began:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
startPoint = [touch locationInView:self];
//NSLog(@"start point:- %f, %f", startPoint.x, startPoint.y);
isHitInPath = NO;
if(!isTextMode)
{
for (NSDictionary *testDict in pathArray)
{
if([((UIBezierPath *)[testDict objectForKey:@"path"]) containsPoint:startPoint])// if starting touch is on an object of bezierpath
{
NSLog(@"touch point is in path: %@ >>>>>>>>>>>>>>", [testDict objectForKey:@"path"]);
isHitInPath = YES;
currentSelectedPath = ((UIBezierPath *)[testDict objectForKey:@"path"]);
CAShapeLayer *centerline = [CAShapeLayer layer];
centerline.path = currentSelectedPath.CGPath;
centerline.strokeColor = [UIColor whiteColor].CGColor;
centerline.fillColor = [UIColor clearColor].CGColor;
centerline.lineWidth = 1.0;
centerline.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:6], [NSNumber numberWithInt:6], nil];
[self.layer addSublayer:centerline];
// showing animation on line
CABasicAnimation *dashAnimation;
dashAnimation = [CABasicAnimation animationWithKeyPath:@"lineDashPhase"];
[dashAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
[dashAnimation setToValue:[NSNumber numberWithFloat:45.0f]];
[dashAnimation setDuration:1.0f];
[dashAnimation setRepeatCount:10000];
[centerline addAnimation:dashAnimation forKey:@"linePhase"];
break;
}
}
}
What should be the correct way of moving (or may be removing old path object and then creating new one of the same size and figure and then move it ) a path object in touches moved.