I have an image. I want to drag that image along a path. Path can be of circular or rectangular shape. If the image is being touched and dragged, it should only travel along the path and should not leave the path. I have tried using Core Graphics and Core animations but can’t find the right way of doing it. I have searched on the net but it always shows how to move an object along a path. Can’t find anything about dragging an object along a path. Also I have found that their is NO method, provided by Apple, to extract points from a UIBezierPath.
Is their anyway of doing this?
The
UIBezierPathclass has an instance method called- (BOOL)containsPoint:. With this method and 2UIBezierPaths, you can check if your object is moving along the path.The trick here is to make 1 path slightly smaller than the first (maybe 2 pixels), while ensuring that both paths have a common center. The path/route that your object must now travel will be the difference of the areas of the bezier paths, which you get from calling
- (BOOL)containsPoint:.If your object is contained within the big
UIBezierPath, but not in the small one, then you know that you are on the correct path.