UIDynamicBehavior Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 7.0 and later.
Declared in
UIDynamicBehavior.h

Overview

A dynamic behavior confers a behavioral configuration on one or more dynamic items for their participation in two-dimensional animation.

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 implement this protocol to use a dynamic animator with custom objects for such purposes as reacting to rotation or position changes computed by an animator—an instance of the UIDynamicAnimator class.

This parent class, UIDynamicBehavior, is inherited by the primitive dynamic behavior classes UIAttachmentBehavior, UICollisionBehavior, UIGravityBehavior, UIDynamicItemBehavior, UIPushBehavior, and UISnapBehavior.

You can subclass UIDynamicBehavior. By using the addChildBehavior: method in an instance of this class or in a custom subclass, you can create composite behaviors of your own design.

When you subclass UIDynamicBehavior, you typically need to provide one or more initializers, along with other housekeeping methods such as those implemented in the iOS primitive dynamic behaviors.

To perform per-step logic in a dynamic animation, provide a block object using the action property.

To access the dynamic animator that a dynamic behavior is associated with, use the dynamicAnimator property. To respond to a dynamic behavior being added to or removed from a dynamic animator, implement the willMoveToAnimator: method.

Tasks

Configuring a Dynamic Behavior

Responding to Changes in the Behavior Tree

Properties

action

The block you want to execute during dynamic animation.

@property(nonatomic, copy) void (^action)(void)
Discussion

The dynamic animator calls the action block on every animation step.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIDynamicBehavior.h

childBehaviors

Returns the array of dynamic behaviors that are children of a custom dynamic behavior. (read-only)

@property(nonatomic, readonly, copy) NSArray *childBehaviors
Discussion

Only custom subclasses of the class can have child behaviors.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIDynamicBehavior.h

dynamicAnimator

The dynamic animator that the dynamic behavior is associated with. (read-only)

@property(nonatomic, readonly) UIDynamicAnimator *dynamicAnimator
Discussion

If the dynamic behavior is not associated with a dynamic animator, the value of this property is nil.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIDynamicBehavior.h

Instance Methods

addChildBehavior:

Adds a dynamic behavior, as a child, to a custom dynamic behavior.

- (void)addChildBehavior:(UIDynamicBehavior *)behavior
Parameters
behavior

The dynamic behavior you want to add as a child.

The parent behavior ignores your use of this method if you:

  • Provide a nil value

  • Provide a behavior instance that you’ve already added to the behavior

Discussion

Call this method only on custom subclasses of the UIDynamicBehavior class.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIDynamicBehavior.h

removeChildBehavior:

Removes a child dynamic behavior from a custom dynamic behavior.

- (void)removeChildBehavior:(UIDynamicBehavior *)behavior
Parameters
behavior

The child dynamic behavior you want to remove.

The parent behavior ignores your use of this method if you:

  • Provide a nil value

  • Provide a behavior instance that is not a child of the parent behavior

Discussion

This method applies only to custom subclasses of the UIDynamicBehavior class. UIKit concrete dynamic behaviors (such as an instance of UICollisionBehavior) cannot have child behaviors.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIDynamicBehavior.h

willMoveToAnimator:

Called when the dynamic behavior is added to, or removed from, a dynamic animator.

- (void)willMoveToAnimator:(UIDynamicAnimator *)dynamicAnimator
Parameters
dynamicAnimator

The dynamic animator that the behavior is being added to, or nil if being removed from an animator.

Discussion

Use this method as the override point for responding to changes in the UIKit Dynamics behavior tree that involve the dynamic behavior.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIDynamicBehavior.h