Using UIKit Dynamics I want to combine a UIAttachmentBehavior and UICollisionBehavior in a way such that the user can drag a view around (using a UIPanGestureRecognizer
) but not leave a certain area.
The problem arises, when the user/UIView collide with the bounds of the collision behavior, as no perpendicular movement is then possible.
I.E. when colliding with the left side of the bounds area one is "stuck" there and can't move up or down, just right. Dragging the UIView back on the exact path used to go there works.
Any help on which UIDynamicItemBehavior works around this is highly appreciated (tried elasticity, friction and resistance, but to no avail).
I think you implemented
UIPanGestureRecognizer
in a wrong way. Try the following example. Just create a new project and paste this code into your ViewController. If you need to reduce the draggable area, you can play with thedragView
function.