Titanium.UI.iOS.DynamicItemBehavior
> Titanium.UI.iOS.DynamicItemBehavior

Base dynamic configuration for an item.

Requires: iOS 7.0 and later

The following APIs are supported on iOS 7 and later.

A dynamic item behavior configures the physics attributes for one or more items. These attributes, such as density and resistance, affects the behavior of the object when other behaviors, such as push forces or collisions, are applied to it. To define a dynamic behavior for an item:

  1. Use the Titanium.UI.iOS.createDynamicItemBehavior method to create and define the behavior.
  2. Use the addItem method to add items to the behavior.
  3. Add the behavior to an Animator object.

Examples

Simple Example

The following example create two blocks, which are pushed towards each other. Because the red block is more dense and has higher resistance than the blue block, the red block moves steadily to the left, while the blue block spins around unpredictably.

var win = Ti.UI.createWindow({backgroundColor: 'white', fullscreen: true});

// Create an Animator object using the window as the coordinate system
var animator = Ti.UI.iOS.createAnimator({referenceView: win});

// Create a red block
var redBlock = Ti.UI.createView({
    backgroundColor: 'red',
    width: 25,
    height: 25,
    top: 25,
    left: 25
});

// Change the physics attributes of the red block
var redDynamic = Ti.UI.iOS.createDynamicItemBehavior({
    density: 20.0,
    angularResistance: 1.0,
    friction: 1.0,
    resistance: 1.0,
    allowsRotation: false
});
redDynamic.addItem(redBlock);

// Apply a left push to the red block
var redPush = Ti.UI.iOS.createPushBehavior({
    pushDirection: {x: 2.0, y: 0.0}
});
redPush.addItem(redBlock);

// Create a blue block
var blueBlock = Ti.UI.createView({
    backgroundColor: 'blue',
    width: 50,
    height: 50,
    top: 25,
    right: 25
});

// Change the physics attributes of the blue block
var blueDynamic = Ti.UI.iOS.createDynamicItemBehavior({
    elasticity: 1.0,
});
blueDynamic.addItem(blueBlock);

// Apply a right push to the blue block
var bluePush = Ti.UI.iOS.createPushBehavior({
    pushDirection: {x: -2.0, y: 0.0}
});
bluePush.addItem(blueBlock);

// Create the collision behavior so the items can collide
var collision = Ti.UI.iOS.createCollisionBehavior();
collision.addItem(redBlock);
collision.addItem(blueBlock);

animator.addBehavior(redDynamic);
animator.addBehavior(redPush);
animator.addBehavior(blueDynamic);
animator.addBehavior(bluePush);
animator.addBehavior(collision);

// Start the animation when the window opens
win.addEventListener('open', function(e){
    animator.startAnimator();
});

win.add(redBlock);
win.add(blueBlock);
win.open();
  • 3.2
  • 3.2
Defined By

Properties

Titanium.UI.iOS.DynamicItemBehavior
: Boolean
Specifies if this item can rotate. ...

Specifies if this item can rotate.

Set to true to enable this behavior or false to disable.

Default: true

Titanium.UI.iOS.DynamicItemBehavior
: Number
Specifies the angular resistance of this item. ...

Specifies the angular resistance of this item.

The greater the value, the greater the angular damping and rotation slows to a stop faster.

Default: 0

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
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.iOS.DynamicItemBehavior
: Number
Specifies the relative mass density of this item. ...

Specifies the relative mass density of this item.

An item's density along with its size determines its effective mass and affects its dynamic behavior.

Default: 1

Titanium.UI.iOS.DynamicItemBehavior
: Number
Specifies the elasticity applied to collisions for this item. ...

Specifies the elasticity applied to collisions for this item.

A value of 0.0 indicates no bounce upon collision, while 1.0 indicates a completely elastic collision.

Default: 0

Titanium.UI.iOS.DynamicItemBehavior
: Number
Specifies the linear resistance of the item when it slides against another item. ...

Specifies the linear resistance of the item when it slides against another item.

A value of 0.0 indicates no friction, while 1.0 indicates strong friction. Use higher numbers to apply even higher friction.

Default: 0

Titanium.UI.iOS.DynamicItemBehavior
items : Titanium.UI.View[]readonly

Items added to this behavior.

Items added to this behavior.

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.iOS.DynamicItemBehavior
: Number
Specifies the linear resistance of this item which reduces linear velocity over time. ...

Specifies the linear resistance of this item which reduces linear velocity over time.

A value of 0.0 indicates no velocity damping.

Default: 0

Defined By

Methods

Titanium.UI.iOS.DynamicItemBehavior
( item, velocity )
Adds a specified angular velocity for the item. ...

Adds a specified angular velocity for the item.

Parameters

  • item : Titanium.UI.View

    Item to add the velocity for.

  • velocity : Number

    Velocity to add or subtract in radians per second. If the current velocity is positive, the item spins clockwise. A negative value means the item spins counter-clockwise.

Returns

  • void
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
Titanium.UI.iOS.DynamicItemBehavior
( item )
Adds an item to this behavior. ...

Adds an item to this behavior.

Parameters

Returns

  • void
Titanium.UI.iOS.DynamicItemBehavior
( item, velocity )
Adds a specified linear velocity for the item. ...

Adds a specified linear velocity for the item.

Parameters

  • item : Titanium.UI.View

    Item to add the velocity for.

  • velocity : Point

    Velocity to add or substract in points per second in the x and y directions.

Returns

  • void
Titanium.UI.iOS.DynamicItemBehavior
( item ) : Number
Returns the angular velocity of the item. ...

Returns the angular velocity of the item.

Parameters

Returns

  • Number
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.iOS.DynamicItemBehavior
( ) : Boolean
Gets the value of the allowsRotation property. ...

Gets the value of the allowsRotation property.

Returns

  • Boolean
Titanium.UI.iOS.DynamicItemBehavior
( ) : Number
Gets the value of the angularResistance property. ...

Gets the value of the angularResistance property.

Returns

  • Number
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
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.iOS.DynamicItemBehavior
( ) : Number
Gets the value of the density property. ...

Gets the value of the density property.

Returns

  • Number
Titanium.UI.iOS.DynamicItemBehavior
( ) : Number
Gets the value of the elasticity property. ...

Gets the value of the elasticity property.

Returns

  • Number
Titanium.UI.iOS.DynamicItemBehavior
( ) : Number
Gets the value of the friction property. ...

Gets the value of the friction property.

Returns

  • Number
Titanium.UI.iOS.DynamicItemBehavior
( ) : Titanium.UI.View[]
Gets the value of the items property. ...

Gets the value of the items property.

Returns

Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.UI.iOS.DynamicItemBehavior
( ) : Number
Gets the value of the resistance property. ...

Gets the value of the resistance property.

Returns

  • Number
Titanium.UI.iOS.DynamicItemBehavior
( item ) : Point
Returns the linear velocity of the item. ...

Returns the linear velocity of the item.

Parameters

Returns

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.iOS.DynamicItemBehavior
( item )
Removes the specified item from this behavior. ...

Removes the specified item from this behavior.

Parameters

Returns

  • void
Titanium.UI.iOS.DynamicItemBehavior
( allowsRotation )
Sets the value of the allowsRotation property. ...

Sets the value of the allowsRotation property.

Parameters

  • allowsRotation : Boolean

    New value for the property.

Returns

  • void
Titanium.UI.iOS.DynamicItemBehavior
( angularResistance )
Sets the value of the angularResistance property. ...

Sets the value of the angularResistance property.

Parameters

  • angularResistance : 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.iOS.DynamicItemBehavior
( density )
Sets the value of the density property. ...

Sets the value of the density property.

Parameters

  • density : Number

    New value for the property.

Returns

  • void
Titanium.UI.iOS.DynamicItemBehavior
( elasticity )
Sets the value of the elasticity property. ...

Sets the value of the elasticity property.

Parameters

  • elasticity : Number

    New value for the property.

Returns

  • void
Titanium.UI.iOS.DynamicItemBehavior
( friction )
Sets the value of the friction property. ...

Sets the value of the friction property.

Parameters

  • friction : 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.iOS.DynamicItemBehavior
( resistance )
Sets the value of the resistance property. ...

Sets the value of the resistance property.

Parameters

  • resistance : Number

    New value for the property.

Returns

  • void