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.

有帮助吗?

解决方案

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top