Contents

UIDynamicItemBehavior

A base dynamic animation configuration for one or more dynamic items.

Declaration

@MainActor class UIDynamicItemBehavior

Overview

A dynamic item is any iOS or custom object that conforms to the UIDynamicItem protocol. The UIView and UICollectionViewLayoutAttributes classes implement this protocol in iOS 7 and later. 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.

One notable and common use of a dynamic item behavior is to confer a velocity to a dynamic item to match the ending velocity of a user gesture.

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

  1. Associate the item with the behavior using the addItem(_:) method, or initialize a new dynamic item behavior with an array of items using the init(items:) method

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

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

You can disable rotation for a dynamic item behavior’s items by returning false from the allowsRotation property. To configure interaction among the behavior’s items, use the elasticity and friction properties.

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

If you add more than one dynamic item behavior to an animator, you effectively create a behavior tree. Only one configuration of a given property applies to any given dynamic item. For a property configured in more than one dynamic item behavior, the last one in the behavior tree, starting from the dynamic animator and going depth first toward the dynamic item, wins.

In the case of an animator with exactly one dynamic item behavior, you can restore default values for all dynamic item behavior properties by removing the behavior. In the case of an animator to which you’ve applied multiple dynamic item behaviors, removing one takes its property contribution out of the behavior tree.

Topics

Initializing and managing a dynamic item behavior

Configuring a dynamic item behavior

See Also

Dynamic items