Question

I am trying to drag a UIView along a tangent path but unable to find resultant point on the line (a CGPath). I have tried by keeping 'x' constant and adding offset to 'y' but this also giving me odd behaviour.

Can any one help me as I am stuck on this.

Was it helpful?

Solution

You can easily compute offset for 'y' by using Pythagorean theorem as you can make a right triangle from tangent line. The calculations are done as,

CGPoint panPoint = [gesture locationInView:self.superview];
CGPoint center = self.center;
pantPoint.x = triangleStartPointFromTop.x;
CGFloat per = fabsf(panPoint.y - triangleStartPointFromTop.y);

CGFloat base = fabsf(per * tanf(triangle.theta));
panPoint.x += base;
center = panPoint;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top