1

I have drawn an arc using:

CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 4.0);
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextMoveToPoint(context, 0,300);
    CGContextAddArcToPoint(context, 125,300, 125,480, 180);//last value is the radius
    CGContextStrokePath(context);

My goal is to place a UImageView at the starting coordinate of this arc and use a UIPanGestureRecognizer to slide it along this arc. Right now I am getting the gesture translation using this line: CGPoint translate = [sender translationInView:self.view]; the sender is a UIPanGestureRecognizer type.

The image should slide down the arc as long as translate.x moves in a positive direction (------->)

Currently I have the image starting at the coordinate (0,300), which is the same starting coordinate for the arc. The image responds to the gesture on the x-axis but the y-value stays at 300. How can I keep a limit on the point translate so that it follows the coordinates of the arc I created?

This is what I currently have, all it does is slide out on the x-axis:

-(void)slide:(UIPanGestureRecognizer *)sender
{
    if([sender state] == UIGestureRecognizerStateBegan)
    {

        startPos = CGPointMake(0, 300);

        minPos = CGPointMake(0, 300);

        maxPos = CGPointMake(125, 480);

    }

    else if ([sender state] == UIGestureRecognizerStateChanged)
    {
        CGPoint translate = [sender translationInView:self.view];
        CGPoint newPos;

        newPos = CGPointMake(startPos.x + translate.x, startPos.y);

        //CGPoint newYPos = CGPointMake(startPos.x + translate.x, <#CGFloat y#>)

        if(newPos.x < minPos.x)
        {
            newPos.x = minPos.x;
            translate = CGPointMake(newPos.x - startPos.x, minPos.y);
        }
        if(newPos.x >= maxPos.x)
        {
            newPos.x = maxPos.x; 
            translate = CGPointMake(newPos.x - startPos.x, maxPos.y);
        }

        [sender setTranslation:translate inView:self.view];

        self.handle.center = newPos; //handle is a UIImageView
    }
}

I think the problem lies in the two if statements I use to limit the x-value. I'm just unsure of how to limit both the x&y-value of CGPoint translate to follow a set curve.

Any help at all is greatly appreciated.

Johnny Gamez
  • 259
  • 6
  • 19

0 Answers0