Class

UIDynamic​Item​Behavior

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.

Overview

A dynamic item is any iOS or custom object that conforms to the UIDynamic​Item protocol. The UIView and UICollection​View​Layout​Attributes 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 UIDynamic​Animator 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 add​Item(_:​) 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 add​Behavior(_:​) 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, read the Overview of UIDynamic​Animator.

You can disable rotation for a dynamic item behavior’s items by returning false from the allows​Rotation 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 UIDynamic​Behavior object and adding a dynamic item behavior with the add​Child​Behavior(_:​) 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.

Symbols

Initializing and Managing a Dynamic Item Behavior

func add​Item(UIDynamic​Item)

Adds a dynamic item to the dynamic item behavior’s item array.

init(items:​ [UIDynamic​Item])

Initializes a dynamic item behavior with an array of dynamic items.

func remove​Item(UIDynamic​Item)

Removes a specific dynamic item from the dynamic item behavior.

var items:​ [UIDynamic​Item]

Returns the set of dynamic items you’ve added to the dynamic item behavior.

Configuring a Dynamic Item Behavior

func add​Angular​Velocity(CGFloat, for:​ UIDynamic​Item)

Adds a specified angular velocity to a dynamic item.

func add​Linear​Velocity(CGPoint, for:​ UIDynamic​Item)

Adds a specified linear velocity to a dynamic item.

var allows​Rotation:​ Bool

Specifies whether rotation is allowed for the behavior’s dynamic items.

var angular​Resistance:​ CGFloat

The angular resistance for the behavior’s dynamic items.

func angular​Velocity(for:​ UIDynamic​Item)

Returns the angular velocity for a specified dynamic item.

func linear​Velocity(for:​ UIDynamic​Item)

Returns the linear velocity for a specified dynamic item.

var density:​ CGFloat

The relative mass density of the behavior’s dynamic items.

var elasticity:​ CGFloat

The amount of elasticity applied to collisions for the behavior’s dynamic items.

var friction:​ CGFloat

The linear resistance for the behavior’s dynamic items when two slide against each other.

var resistance:​ CGFloat

The linear resistance for the behavior’s dynamic items, which reduces their linear velocity over time.

var charge:​ CGFloat

The charge associated with the item.

var is​Anchored:​ Bool

A Boolean value indicating whether the item is anchored to its current position.

Relationships