Titanium.UI.Animation
> Titanium.UI.Animation

The Animation object defines an animation that can be applied to a view.

An animation object describes the properties of an animation. At its most basic, an animation object represents a single-phase animation with an end state and a duration.

When animate is called on a View, the view is animated from its current state to the state described by the animation object. The properties that can be animated include the view's position, size, colors, transformation matrix and opacity.

Animations can be set to reverse themselves automatically on completion, and to repeat a given number of times. For more complicated effects, multiple animations can be combined in sequence, starting one animation when the previous animation completes.

Use the Titanium.UI.createAnimation method to create an animation object.

Note that when you animate a view's size or position, the actual layout properties (such as top, left, width, height) are not changed by the animation. See the description of the animate method for more information.

iOS Platform Notes

iOS supports both 2D and 3D matrix transformations in animations.

In iOS, you can also specify an animation curve or easing function to control the pace of the animation. To use an easing function, set the animation's curve property to one of the ANIMATION_CURVE constants defined in Titanium.UI. For example, ANIMATION_CURVE_EASE_IN specifies an animation that starts slowly and then speeds up.

Finally, iOS also supports transitions between windows or views. You can create a transition by creating an animation object and setting the view property to the view you want to transition to. The transition property specifies the transition effect to apply. Use one of the transition style constants defined in Titanium.UI.iOS.AnimationStyle.

Android Platform Notes

Android supports 2D matrix transformations. Note that the 2DMatrix.rotate method operates differently on Android. Called with a single argument, it rotates from zero to the specified angle. That is, it ignores any existing rotation. Called with two arguments, it interprets the first argument as a "from" angle and the second argument as a "to" angle.

Android doesn't support any animation curves or easing functions. Animations always interpolate linearly between the start state and the end state.

Examples

Simple Animation Applied to a View

Create a simple animation and apply it to the view. In this example, the view will animate from red to black to orange over 2 seconds.

var view = Titanium.UI.createView({
  backgroundColor:'red'
});
var animation = Titanium.UI.createAnimation();
animation.backgroundColor = 'black';
animation.duration = 1000;
var animationHandler = function() {
  animation.removeEventListener('complete',animationHandler);
  animation.backgroundColor = 'orange';
  view.animate(animation);
};
animation.addEventListener('complete',animationHandler);
view.animate(animation);

Animation Using Matrix Transforms

The following example uses a transformation matrix to animate a view when the view is clicked. The animation rotates and scales the view, then returns it to its original size and position. The entire animation is repeated three times.

var box = Ti.UI.createView({
  backgroundColor : 'red',
  height : '100',
  width : '100'
});
win.add(box);

box.addEventListener('click', function() {
  var matrix = Ti.UI.create2DMatrix();
  matrix = matrix.rotate(180);
  matrix = matrix.scale(2, 2);
  var a = Ti.UI.createAnimation({
    transform : matrix,
    duration : 2000,
    autoreverse : true,
    repeat : 3
  });
  box.animate(a);
});

win.add(box);

Using an anchorPoint (Android and iOS)

Create a button and a blue square view. For each click of the button, apply a 90 degree rotation animation pivoted at one of a series of anchor points. In particular, note that an anchor point is configured using the anchorPoint property for Android and the Titanium.UI.View.anchorPoint property for iOS.

var animationType = [
  { name: 'Top Left', anchorPoint: {x:0, y:0} },
  { name: 'Top Right', anchorPoint: {x:1, y:0} },
  { name: 'Bottom Left', anchorPoint: {x:0, y:1} },
  { name: 'Bottom Right', anchorPoint: {x:1, y:1} },
  { name: 'Center', anchorPoint: {x:0.5, y:0.5} }
];
var animationTypeLength = animationType.length;
var animationCount = 0;
var animationTypePointer = 0;

var t = Ti.UI.create2DMatrix();
t = t.rotate(90);

// animation properties
var a = {
  transform: t,
  duration: 2000,
  autoreverse: true
};

Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow();

var view = Ti.UI.createView({
  backgroundColor:'#336699',
  width:100, height:100
});
win.add(view);

var button = Ti.UI.createButton({
  title:'Animate ' + animationType[animationTypePointer].name,
  height: (Ti.UI.Android) ? 80 : 40,
  width: (Ti.UI.Android) ? 300 : 200,
  top:30
});
win.add(button);

function updateButton(name){
  button.title = 'Animate ' + name;
}

button.addEventListener('click', function(){
  // set new anchorPoint on animation for Android
  a.anchorPoint = animationType[animationTypePointer].anchorPoint;

  // set new anchorPoint on view for iOS
  view.anchorPoint = animationType[animationTypePointer].anchorPoint;

  animationCount++;

  // determine position of next object in animationType array or return to first item
  // using modulus operator
  animationTypePointer = animationCount % animationTypeLength;

  // animate view, followed by callback to set next button title
  view.animate(a, function(){
    updateButton(animationType[animationTypePointer].name);
  });
});

win.open();
  • 0.9
  • 0.9
  • 0.9
Defined By

Properties

Titanium.UI.Animation
anchorPoint : Point

Coordinate of the view about which to pivot an animation.

Coordinate of the view about which to pivot an animation.

Used on Android only. For iOS, use Titanium.UI.View.anchorPoint.

Anchor point is specified as a fraction of the view's size. For example, {0, 0} is at the view's top-left corner, {0.5, 0.5} at its center and {1, 1} at its bottom-right corner.

See the "Using an anchorPoint" example for a demonstration.

  • 0.9
apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Titanium.UI.Animation
: Boolean
Specifies if the animation should be replayed in reverse upon completion. ...

Specifies if the animation should be replayed in reverse upon completion.

Default: false

Titanium.UI.Animation
backgroundColor : String

Value of the backgroundColor property at the end of the animation, as a color name or hex triplet.

Value of the backgroundColor property at the end of the animation, as a color name or hex triplet.

For information about color values, see the "Colors" section of Titanium.UI.

Titanium.UI.Animation
bottom : Number

Value of the bottom property at the end of the animation.

Value of the bottom property at the end of the animation.

Indicates if the proxy will bubble an event to its parent. ...

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.UI.Animation
center : Object

Value of the center property at the end of the animation.

Value of the center property at the end of the animation.

Titanium.UI.Animation
color : String

Value of the color property at the end of the animation, as a color name or hex triplet.

Value of the color property at the end of the animation, as a color name or hex triplet.

For information about color values, see the "Colors" section of Titanium.UI.

  • 0.9
  • 0.9
Titanium.UI.Animation
: Number
Animation curve or easing function to apply to the animation. ...

Animation curve or easing function to apply to the animation.

This API can be assigned the following constants:

  • 0.9
  • 0.9
Titanium.UI.Animation
delay : Number

Delay, in milliseconds before starting the animation.

Delay, in milliseconds before starting the animation.

Titanium.UI.Animation
duration : Number

Duration of the animation, in milliseconds.

Duration of the animation, in milliseconds.

Titanium.UI.Animation
height : Number

Value of the height property at the end of the animation.

Value of the height property at the end of the animation.

Titanium.UI.Animation
left : Number

Value of the left property at the end of the animation.

Value of the left property at the end of the animation.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Titanium.UI.Animation
opacity : Number

Value of the opacity property at the end of the animation.

Value of the opacity property at the end of the animation.

Titanium.UI.Animation
opaque : Boolean

Value of the opaque property at the end of the animation.

Value of the opaque property at the end of the animation.

  • 0.9
  • 0.9
Titanium.UI.Animation
: Number
Number of times the animation should be performed. ...

Number of times the animation should be performed.

If autoreverse is true, then one repeat of the animation consists of the animation being played once forward, and once backward.

Default: 1 (no repeat)

Titanium.UI.Animation
right : Number

Value of the right property at the end of the animation.

Value of the right property at the end of the animation.

Titanium.UI.Animation
top : Number

Value of the top property at the end of the animation.

Value of the top property at the end of the animation.

Animate the view from its current tranform to the specified transform.

Animate the view from its current tranform to the specified transform.

Over the course of the animation, the view interpolates from its current transform to the specified transform.

3D transforms are only supported on iOS.

Titanium.UI.Animation
transition : Number

Transition type to use during a transition animation.

Transition type to use during a transition animation.

The new view being transitioned to should NOT be a child of another view or of the animating view. The animation replaces the current view from the view heirarchy and adds the new view to it.

This API can be assigned the following constants:

  • 0.9
  • 0.9
Titanium.UI.Animation
view : Titanium.UI.View

New view to transition to.

New view to transition to.

Specify the transition property with one of the transition style constants defined in Titanium.UI.iOS.AnimationStyle to select the effect to apply.

The new view being transitioned to should NOT be a child of another view or of the animating view. The animation replaces the current view from the view heirarchy and adds the new view to it.

  • 0.9
  • 0.9
Titanium.UI.Animation
visible : Boolean

Value of the visible property at the end of the animation.

Value of the visible property at the end of the animation.

  • 0.9
  • 0.9
Titanium.UI.Animation
width : Number

Value of the width property at the end of the animation.

Value of the width property at the end of the animation.

Titanium.UI.Animation
zIndex : Number

Value of the zIndex property at the end of the animation.

Value of the zIndex property at the end of the animation.

Refer to Titanium.UI.View.zIndex for an explanation of z-index.

  • 0.9
  • 0.9
Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Titanium.UI.Animation
( ) : Point
Gets the value of the anchorPoint property. ...

Gets the value of the anchorPoint property.

  • 0.9

Returns

Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Titanium.UI.Animation
( ) : Boolean
Gets the value of the autoreverse property. ...

Gets the value of the autoreverse property.

Returns

  • Boolean
Titanium.UI.Animation
( ) : String
Gets the value of the backgroundColor property. ...

Gets the value of the backgroundColor property.

Returns

  • String
Titanium.UI.Animation
( ) : Number
Gets the value of the bottom property. ...

Gets the value of the bottom property.

Returns

  • Number
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.UI.Animation
( ) : Object
Gets the value of the center property. ...

Gets the value of the center property.

Returns

  • Object
Titanium.UI.Animation
( ) : String
Gets the value of the color property. ...

Gets the value of the color property.

  • 0.9
  • 0.9

Returns

  • String
Titanium.UI.Animation
( ) : Number
Gets the value of the curve property. ...

Gets the value of the curve property.

  • 0.9
  • 0.9

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the delay property. ...

Gets the value of the delay property.

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the duration property. ...

Gets the value of the duration property.

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the height property. ...

Gets the value of the height property.

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the left property. ...

Gets the value of the left property.

Returns

  • Number
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.UI.Animation
( ) : Number
Gets the value of the opacity property. ...

Gets the value of the opacity property.

Returns

  • Number
Titanium.UI.Animation
( ) : Boolean
Gets the value of the opaque property. ...

Gets the value of the opaque property.

  • 0.9
  • 0.9

Returns

  • Boolean
Titanium.UI.Animation
( ) : Number
Gets the value of the repeat property. ...

Gets the value of the repeat property.

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the right property. ...

Gets the value of the right property.

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the top property. ...

Gets the value of the top property.

Returns

  • Number
Gets the value of the transform property. ...

Gets the value of the transform property.

Returns

Titanium.UI.Animation
( ) : Number
Gets the value of the transition property. ...

Gets the value of the transition property.

  • 0.9
  • 0.9

Returns

  • Number
Titanium.UI.Animation
( ) : Titanium.UI.View
Gets the value of the view property. ...

Gets the value of the view property.

  • 0.9
  • 0.9

Returns

Titanium.UI.Animation
( ) : Boolean
Gets the value of the visible property. ...

Gets the value of the visible property.

  • 0.9
  • 0.9

Returns

  • Boolean
Titanium.UI.Animation
( ) : Number
Gets the value of the width property. ...

Gets the value of the width property.

Returns

  • Number
Titanium.UI.Animation
( ) : Number
Gets the value of the zIndex property. ...

Gets the value of the zIndex property.

  • 0.9
  • 0.9

Returns

  • Number
Removes the specified callback as an event listener for the named event. ...

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Titanium.UI.Animation
( anchorPoint )
Sets the value of the anchorPoint property. ...

Sets the value of the anchorPoint property.

  • 0.9

Parameters

  • anchorPoint : Point

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( autoreverse )
Sets the value of the autoreverse property. ...

Sets the value of the autoreverse property.

Parameters

  • autoreverse : Boolean

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( backgroundColor )
Sets the value of the backgroundColor property. ...

Sets the value of the backgroundColor property.

Parameters

  • backgroundColor : String

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( bottom )
Sets the value of the bottom property. ...

Sets the value of the bottom property.

Parameters

  • bottom : Number

    New value for the property.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( center )
Sets the value of the center property. ...

Sets the value of the center property.

Parameters

  • center : Object

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( color )
Sets the value of the color property. ...

Sets the value of the color property.

  • 0.9
  • 0.9

Parameters

  • color : String

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( curve )
Sets the value of the curve property. ...

Sets the value of the curve property.

  • 0.9
  • 0.9

Parameters

  • curve : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( delay )
Sets the value of the delay property. ...

Sets the value of the delay property.

Parameters

  • delay : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( duration )
Sets the value of the duration property. ...

Sets the value of the duration property.

Parameters

  • duration : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( height )
Sets the value of the height property. ...

Sets the value of the height property.

Parameters

  • height : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( left )
Sets the value of the left property. ...

Sets the value of the left property.

Parameters

  • left : Number

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.UI.Animation
( opacity )
Sets the value of the opacity property. ...

Sets the value of the opacity property.

Parameters

  • opacity : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( opaque )
Sets the value of the opaque property. ...

Sets the value of the opaque property.

  • 0.9
  • 0.9

Parameters

  • opaque : Boolean

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( repeat )
Sets the value of the repeat property. ...

Sets the value of the repeat property.

Parameters

  • repeat : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( right )
Sets the value of the right property. ...

Sets the value of the right property.

Parameters

  • right : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( top )
Sets the value of the top property. ...

Sets the value of the top property.

Parameters

  • top : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( transform )
Sets the value of the transform property. ...

Sets the value of the transform property.

Parameters

Returns

  • void
Titanium.UI.Animation
( transition )
Sets the value of the transition property. ...

Sets the value of the transition property.

  • 0.9
  • 0.9

Parameters

  • transition : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( view )
Sets the value of the view property. ...

Sets the value of the view property.

  • 0.9
  • 0.9

Parameters

Returns

  • void
Titanium.UI.Animation
( visible )
Sets the value of the visible property. ...

Sets the value of the visible property.

  • 0.9
  • 0.9

Parameters

  • visible : Boolean

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( width )
Sets the value of the width property. ...

Sets the value of the width property.

Parameters

  • width : Number

    New value for the property.

Returns

  • void
Titanium.UI.Animation
( zIndex )
Sets the value of the zIndex property. ...

Sets the value of the zIndex property.

  • 0.9
  • 0.9

Parameters

  • zIndex : Number

    New value for the property.

Returns

  • void
Defined By

Events

Titanium.UI.Animation
Fired when the animation completes. ...

Fired when the animation completes.

Properties

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.UI.Animation
Fired when the animation starts. ...

Fired when the animation starts.

Properties

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •