Code: Select all
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint checkPoint = [touch locationInView:self.view];
// Allows grabbing and pushing of circles
for (UIView *circleView in self.view.subviews)
{
float threshold = 100;
CGPoint center;
float distx = circleView.center.x - checkPoint.x;
float disty = circleView.center.y - checkPoint.y;
float dist = sqrt(distx * distx + disty * disty);
// Can push circle
else if (dist < threshold)
{
center.x = checkPoint.x + threshold * distx / dist;
center.y = checkPoint.y + threshold * disty / dist;
circleView.center = center;
}
}
}
Thanks.