How do I detect a touch on a UIBezierPath and move a ball along that?

前端 未结 5 2097
孤城傲影
孤城傲影 2020-12-05 12:20

How do I move a ball along a specific UiBezierPath? Is that possible?

I\'ve tried everything including doing a hit test using

-(BOOL)containsPoint:(         


        
5条回答
  •  心在旅途
    2020-12-05 12:55

    Mathematically, you can not determine if a point inside a curve, a pure mathematical one, as a curve has no surface. What you can do, is test if the point is inside the surface defined by the bounds of the closed curve created by CGPathCreateCopyByStrokingPath with CGPathContainsPoint. It creates the curve that is filled to render your curve on the screen.

    If CGPathCreateCopyByStrokingPath is called with its parameter:CGFloat lineWidth less or equal to the minimum radius of curvature of the original curve, it will not self-intersect. Also the original curve should not self intersects.

    If CGPathContainsPoint returns true, and both conditions I mentioned are met, you are guaranteed to find one and only point on the curve that is at a distance of lineWidth. There is no algebraic solution to this, so you have to find an approximate point on the curve that is close to the touched point with the method described here: Find a point, a given distance, along a simple cubic bezier curve. (On an iPhone!)

提交回复
热议问题