ベジェパスオブジェクトから線と円を描画した後、これらのオブジェクトを画面上で移動したいと思います。最初にパスオブジェクトに触れると、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;
}
}
}
移動する正しい方法は何であるか(または、古いパスオブジェクトを削除してから、同じサイズと図の新しいオブジェクトを作成してから移動することもできます)、タッチでパスオブジェクトを移動します。