1
從貝塞爾路徑對象中繪製直線和圓後,我想現在將這些對象移動到屏幕上。首先,當我觸及路徑對象時,它應該被選中,我已經使用containsPoint:方法。我如何移動一個UIBezierPath對象與touchesMoved?
現在我想讓這個選定的物體在我拖動我的方格時移動。我想知道如何將一個撫摸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;
}
}
}
應該是什麼運動的正確方法(或者可以刪除舊路徑對象,然後創建相同的大小,圖的新的,然後移動它)觸摸移動的路徑對象。
這可能是一個[一個有用的回答類似的問題(HTTP://計算器。 com/questions/8109482/is-uibezierpath-the-best-way-make-a-movable-rounded-rectangle) – bbarnhart
對不起,但多數民衆贊成在不同的問題 – Rakesh
你的問題有什麼不同? – bbarnhart