从贝塞尔路径对象绘制线条和圆圈后,我现在想在屏幕上移动这些对象。首先,当我触摸路径对象时,它应该被选中,这是我使用 containsPoint: 方法完成的。
现在我希望这个选定的对象应该在我拖动手指时移动。我想知道如何将描边的 bezierpath 对象移动到新位置?
这是我开始接触的代码:
-(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;
}
}
}
移动路径对象的正确方法应该是什么(或者可能是删除旧路径对象,然后创建相同大小和图形的新路径对象,然后移动它)触摸移动的路径对象。