# Titanium.UI.iOS.Animator

> Provides support for the built-in iOS dynamic animations

- Source: https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.UI.iOS.Animator
- Titanium SDK version: 12.5.0
- Kind: proxy
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0
- Extends: Titanium.Proxy
- Inheritance: Titanium.Proxy

The animator provides physics-related capabilities and animations using the iOS physics engine.
Each animator is independent of other animators you create.  An animator is comprised of
behaviors and items. Behaviors define the rules of the animation, while items are the
view objects to be animated. An item in the animator can be given
multiple behaviors as long as those behaviors belong to the same animator.

To use these dynamic animations, first create the items to animate, then:

**1.** Create an animator using the [Titanium.UI.iOS.createAnimator](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.md#createAnimator) method. 

**2.** Set the [referenceView](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.Animator.md#referenceView) property to establish the
   coordinate system for the animations.

**3.** Create and add items to one or more of the following behaviors:

  * [Titanium.UI.iOS.AnchorAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AnchorAttachmentBehavior.md)
  * [Titanium.UI.iOS.CollisionBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.CollisionBehavior.md)
  * [Titanium.UI.iOS.DynamicItemBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.DynamicItemBehavior.md)
  * [Titanium.UI.iOS.GravityBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.GravityBehavior.md)
  * [Titanium.UI.iOS.PushBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.PushBehavior.md)
  * [Titanium.UI.iOS.SnapBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.SnapBehavior.md)
  * [Titanium.UI.iOS.ViewAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.ViewAttachmentBehavior.md)

**4.** Add these behaviors to the animator with the [addBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.Animator.md#addBehavior) method.

**5.** Start the animator with [startAnimator](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.Animator.md#startAnimator) method.

Once all items are at rest, the animator automatically pauses, and resumes if a behavior
parameter changes, or a behavior or item is added or removed.

See the behaviors listed above for examples of animating items.

#### Reference View

The Titanium view object set to the Animator's [referenceView](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.Animator.md#referenceView)
property establishes the coordinate system for the animation behaviors and items.  Each item that
needs to be animated must be a child of the reference view.

By default, when you create a collision behavior, the behavior uses the edge's of the reference
view as its boundary, so any item within this view cannot be pushed out of it.

Use the following lists as references when specifying your animation behaviors.

**Points**

The following list notes the location of notable points in the coordinate system, where WIDTH and
HEIGHT are the width and height of the reference view, respectively.

  * Top-left corner: (0,0)
  * Top-right corner: (WIDTH, 0)
  * Center: (WIDTH/2, HEIGHT/2)
  * Bottom-left corner: (0, HEIGHT)
  * Bottom-right corner: (WIDTH, HEIGHT)

Note that on iOS a point is equivalent to a display pixel.

**Vectors**

Gravity and push forces may be specified as vectors with the `gravityDirection` and
`pushDirection` properties, respectively.  The following list notes the direction and its
corresponding vector:

  * Left: (-x,0)
  * Right: (+x,0)
  * Up: (0,-y)
  * Down: (0,+y)

**Angles**

Gravity and push forces may be specified with the `angle` and `magnitude` properties.
Specify all angle values as radians (360 degrees = 2 * pi radians).  The following list notes
the direction and its corresponding angle:

  * Right: 0 or 2 * pi
  * Down: pi / 2
  * Left: pi
  * Up: pi / 2 * 3

## Properties

### behaviors

- Type: Array<Titanium.Proxy>
- Platforms: iPhone, iPad, macOS

Behaviors associated with this animator.

### referenceView

- Type: Titanium.UI.View
- Platforms: iPhone, iPad, macOS

Titanium View object to initialize as the reference view for the animator.

When adding behavior and dynamic items to the animator, the animator bases its
coordindate system on the reference view.

### running

- Type: Boolean
- Platforms: iPhone, iPad, macOS
- Permission: read-only

Returns `true` if the animator is running else `false`.

## Methods

### addBehavior

- Platforms: iPhone, iPad, macOS

Adds a dynamic behavior to the animator.

Specify an instance of one of the following Titanium behavior proxies:

  * [Titanium.UI.iOS.AnchorAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AnchorAttachmentBehavior.md)
  * [Titanium.UI.iOS.CollisionBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.CollisionBehavior.md)
  * [Titanium.UI.iOS.DynamicItemBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.DynamicItemBehavior.md)
  * [Titanium.UI.iOS.GravityBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.GravityBehavior.md)
  * [Titanium.UI.iOS.PushBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.PushBehavior.md)
  * [Titanium.UI.iOS.SnapBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.SnapBehavior.md)
  * [Titanium.UI.iOS.ViewAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.ViewAttachmentBehavior.md)

Parameters:

- `behavior` (Titanium.Proxy): Behavior to add to the animator.

### removeAllBehaviors

- Platforms: iPhone, iPad, macOS

Removes all behaviors from this animator.

### removeBehavior

- Platforms: iPhone, iPad, macOS

Removes the specified behavior from the animator.

Specifiy an instance of one of the following Titanium behavior proxies:

  * [Titanium.UI.iOS.AnchorAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AnchorAttachmentBehavior.md)
  * [Titanium.UI.iOS.CollisionBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.CollisionBehavior.md)
  * [Titanium.UI.iOS.DynamicItemBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.DynamicItemBehavior.md)
  * [Titanium.UI.iOS.GravityBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.GravityBehavior.md)
  * [Titanium.UI.iOS.PushBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.PushBehavior.md)
  * [Titanium.UI.iOS.SnapBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.SnapBehavior.md)
  * [Titanium.UI.iOS.ViewAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.ViewAttachmentBehavior.md)

Parameters:

- `behavior` (Titanium.Proxy): Behavior to remove from the animator.

### startAnimator

- Platforms: iPhone, iPad, macOS

Starts the animation behaviors.

### stopAnimator

- Platforms: iPhone, iPad, macOS

Stops the animation behaviors.

### updateItemUsingCurrentState

- Platforms: iPhone, iPad, macOS

Updates the animator's state information with the current state of the specified item.

When an item is first added to the animator, the animator reads the initial state of the
item, then takes responsibility for updating it.  If you actively make changes to the item's properties,
such as changing its position or dimensions, use this method to update the item's new state.

Parameters:

- `item` (Titanium.UI.View): Item to update with new state information.

## Events

### pause

- Platforms: iPhone, iPad, macOS

Fired when the animator paused its animations.

### resume

- Platforms: iPhone, iPad, macOS

Fired when the animator resumes its animations.

## Inherited members

6 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `removeEventListener`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

