iOS Developer Library


UIKit Framework Reference UISnapBehavior Class Reference

Deployment Target:

On This Page


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 initWithItem:snapToPoint: 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 Class Reference.

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.

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



    init(item item: UIDynamicItem, snapToPoint point: CGPoint)


    - (instancetype _Nonnull)initWithItem:(id<UIDynamicItem> _Nonnull)item snapToPoint:(CGPoint)point



    The dynamic item that you want to apply a snap behavior to.


    The point that you want the dynamic item to snap to. The coordinate system for the point parameter depends on how you initialize the dynamic animator you’re adding the snap behavior to, as described in the overview of UIDynamicAnimator Class Reference.

    Return Value

    The initialized snap behavior, or nil if there was a problem initializing the object.


    At the conclusion of a snap, the rotation value (as indicated by the transform property) for a dynamic item is 0.


    Available in iOS 7.0 and later.

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



    var damping: CGFloat


    @property(nonatomic, assign) CGFloat damping


    The valid range for damping extends from 0.0, for minimum oscillation, through 1.0, for maximum oscillation. The default value is 0.5.


    Available in iOS 7.0 and later.