A dynamic item behavior represents a base dynamic animation configuration for one or more dynamic items. Each of its properties overrides a corresponding default value.
- iOS 7.0+
- tvOS 7.0+
A dynamic item is any iOS or custom object that conforms to the
UIDynamicItem protocol. The
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
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:
Enable the behavior by adding it to an animator using the
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, read the Overview of
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
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
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.