How can I constrain the drag-path of a button so that it can only be dragged to the centre of the screen from any point I want?
I know the current position of the UIButton and the centre coordinates.
I need the current x and y formula for the drag event.
This should do it. Save the start position of the drag, get the current position on each move event. Pass those to this function. It will answer a vector which can be applied to the button’s frame.
The gist of the calculation is to determine a magnitude by choosing the smallest component of the drag (x or y) and answering a vector with the same magnitude in both dimensions (preserving the signs over both axes).
Call it like this:
You can fool around with the magnitude calculation.. largest component, smallest, average, etc. As long as the result is symmetrical in both dimensions.