A snap behavior defines a dynamic item’s movement to a specified point; the movement proceeds with a spring-like effect, ending with an oscillation whose amount you can set.


A dynamic item is any iOS or custom object that conforms to the UIDynamicItem protocol. The UIView and UICollectionViewLayoutAttributes classes implement this protocol starting in iOS 7.0. You can use a custom object as a dynamic item for such purposes as reacting to rotation or position changes computed by a dynamic animator—an instance of the UIDynamicAnimator class.

To use a snap behavior with a dynamic item, perform these two steps:

  1. Initialize a new snap behavior with the item using the init(item:snapTo:) method

  2. Enable the behavior by adding it to an animator using the addBehavior(_:) method

The coordinate system that pertains to a snap behavior, and the types of dynamic items you can use with the behavior, depend on how you initialized the associated animator. For details, read the Overview of UIDynamicAnimator.

You can include a snap behavior in a custom, composite behavior by starting with a UIDynamicBehavior object and adding a snap behavior with the addChildBehavior(_:) method. If you want to influence a snap behavior at each step of a dynamic animation, implement the inherited action method.


Initializing a Snap Behavior

init(item: UIDynamicItem, snapTo: CGPoint)

Initializes a snap behavior with a dynamic item and a snap point.

Configuring a Snap Behavior

var snapPoint: CGPoint

The point to which to snap.

var damping: CGFloat

The amount of oscillation of a dynamic item during the conclusion of a snap.


Inherits From