0
votes

I've been exploring iOS animations and I'm trying to find out if there is a simple way to restrict animation movement to within a certain area. For example, lets say you are using a pan gesture recognizer to drag a UIView around the screen. Is there a simple way to enforce that the frame of the UIView does not move beyond a specified location?

The way i've currently been approaching it is to take the UIView, calculate the location of the edges, and within my handlePan method, simply return (ie don't adjust the center point) if the frame is touching the boundary. Is there a more elegant way to do this? Even if only along a single axis?

Thanks!

1
Actually this has nothing to do with "animations" in UIKit. This is about gesture recognizers and tracking. You might want to find a more descriptive title.Daniel Rinser

1 Answers

0
votes

I actually am doing that in one project and basically well, I am using the "non elegant" way. I have a set of coordinates "boundaries" from which the view I am dragging should not pass. Although there better ways to do this than others. For instance for a smoother experience:

  • Compare the X axis independently for the Y axis. What I was doing in the beginning was to compare the X and the Y in the same if sentence.

Extra: Check this project to get some ideas.