Drag along the way to Iphone

I have an image. I want to drag this image along the way. The path can be round or rectangular. If the image touches and is dragged, it should only move along the path and should not leave the path. I tried using Core Graphics and Core animations, but can't find the right way to do this. I searched on the net but always shows how to move an object along a path. Cannot find anything about dragging an object along a path. I also found that their NO method provided by Apple extracts points from UIBezierPath.

Are they all doing this?

+4
source share
1 answer

The UIBezierPath class has an instance method called - (BOOL)containsPoint: Using this method and 2 UIBezierPath s you can check if your object is moving along the path.

 +---------+ |xxxxxxxxx| |x+-----+x| |x| |x| |x| |x| |x| |x| |x+-----+x| |xxxxxxxxx| +---------+ 

The trick here is to make 1 path slightly smaller than the first (maybe 2 pixels), ensuring that both paths have a common center. The path / route your object should move will be the difference in the areas of the bezier paths that you get from the call - (BOOL)containsPoint:

If your object is contained in a large UIBezierPath , but not in a small one, then you know that you are on the right track.

0
source

Source: https://habr.com/ru/post/1437197/


All Articles