Titanium.UI.iOS.PushBehavior
> Titanium.UI.iOS.PushBehavior

Continuous or instantaneous force to apply to an item.

Requires: iOS 7.0 and later

The following APIs are supported on iOS 7 and later.

A push behavior configures the continuous or instaneous force to apply to one or more items. To define a push behavior:

  1. Use the Titanium.UI.iOS.createPushBehavior method to create and define the behavior.
  2. To define a force vector, either set the angle and magnitude properties, or set the pushDiretion property.
  3. Use the addItem method to add items to the behavior.
  4. Add the behavior to an Animator object.

Examples

Simple Example

The following example generates a random push force on the block when it stops.

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});

var block = Ti.UI.createView({
    width: 100,
    height: 100,
    backgroundColor: 'blue',
    transform: Ti.UI.create2DMatrix({ rotate: 45 })
});

// Create a default collision behavior, using the window edges as boundaries
var collision = Ti.UI.iOS.createCollisionBehavior();
collision.addItem(block);
animator.addBehavior(collision);

// Push the block down when the application first starts
var push = Ti.UI.iOS.createPushBehavior({
    pushDirection: {x: 0.0, y: 1.0},
    pushMode: Ti.UI.iOS.PUSH_MODE_INSTANTANEOUS
});
push.addItem(block);
animator.addBehavior(push);

// Apply a new push behavior when the item stops
animator.addEventListener('pause', function(e){
    push.angle = 2 * Math.PI * Math.random();
    push.magnitude = Math.random() * 5 + 5;
    push.active = true;
});

animator.addEventListener('resume', function(e){
    Ti.API.info(JSON.stringify(
        'push force: ' + push.magnitude * 100 + " points/s^2 @ "
        + (push.angle * 360 / (2 * Math.PI)) + " degrees")
    );
});

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

win.add(block);
win.open();
  • 3.2
  • 3.2
Defined By

Properties

Titanium.UI.iOS.PushBehavior
: Boolean
State of the push behavior's force. ...

State of the push behavior's force.

Set to true to activate the force or false to deactivate it. Use this property rather than removing and re-adding the behavior to the animator.

Default: true

Titanium.UI.iOS.PushBehavior
: Number
Specifies the angle of the force vector in radians. ...

Specifies the angle of the force vector in radians.

To configure the force vector, you need to also specify the magnitude property.

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.PushBehavior
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.PushBehavior
: Number
Specifies the magnitude of the force vector. ...

Specifies the magnitude of the force vector.

A value of 1.0 represents an acceleration of 100 points per second squared if the item is 100 x 100 points with a density of 1.0.

To configure the push vector, you need to also specify the angle property.

Default: 0

Titanium.UI.iOS.PushBehavior
: Point
Specifies the direction of the force vector as an x, y pair. ...

Specifies the direction of the force vector as an x, y pair.

For example, specifiying {x: 0.0, y: 1.0} indicates a positive upward force of 100 points per second squared if the item is 100 x 100 points with a density of 1.0.

Specifiying a negative value reverses the direction of the force.

Default: (0,0)

Titanium.UI.iOS.PushBehavior
: Number
Specifies the push mode. ...

Specifies the push mode.

This API can be assigned the following constants:

Default: Titanium.UI.iOS.PUSH_MODE_CONTINUOUS

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

Adds an item to this behavior.

Parameters

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.iOS.PushBehavior
( ) : Boolean
Gets the value of the active property. ...

Gets the value of the active property.

Returns

  • Boolean
Titanium.UI.iOS.PushBehavior
( ) : Number
Gets the value of the angle property. ...

Gets the value of the angle 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.PushBehavior
( ) : 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.PushBehavior
( ) : Number
Gets the value of the magnitude property. ...

Gets the value of the magnitude property.

Returns

  • Number
Titanium.UI.iOS.PushBehavior
( ) : Point
Gets the value of the pushDirection property. ...

Gets the value of the pushDirection property.

Returns

Titanium.UI.iOS.PushBehavior
( ) : Number
Gets the value of the pushMode property. ...

Gets the value of the pushMode property.

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

Removes the specified item from this behavior.

Parameters

Returns

  • void
Titanium.UI.iOS.PushBehavior
( active )
Sets the value of the active property. ...

Sets the value of the active property.

Parameters

  • active : Boolean

    New value for the property.

Returns

  • void
Titanium.UI.iOS.PushBehavior
( angle )
Sets the value of the angle property. ...

Sets the value of the angle property.

Parameters

  • angle : 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
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.UI.iOS.PushBehavior
( magnitude )
Sets the value of the magnitude property. ...

Sets the value of the magnitude property.

Parameters

  • magnitude : Number

    New value for the property.

Returns

  • void
Titanium.UI.iOS.PushBehavior
( pushDirection )
Sets the value of the pushDirection property. ...

Sets the value of the pushDirection property.

Parameters

  • pushDirection : Point

    New value for the property.

Returns

  • void
Titanium.UI.iOS.PushBehavior
( pushMode )
Sets the value of the pushMode property. ...

Sets the value of the pushMode property.

Parameters

  • pushMode : Number

    New value for the property.

Returns

  • void