Titanium.UI.2DMatrix
> Titanium.UI.2DMatrix

The 2D Matrix is an object for holding values for an affine transformation matrix.

A 2D matrix is used to rotate, scale, translate, or skew the objects in a two-dimensional space. A 2D affine transformation can be represented by a 3 by 3 matrix:

ab0
cd0
txty1

The third column is constant (0,0,1).

On iOS, the matrix terms, a, b, c, d, tx, and ty, are available as properties. On Android, the matrix terms are not available as properties.

Use the Titanium.UI.create2DMatrix method to create a new 2D matrix. You can pass an optional MatrixCreationDict dictionary to the method to initialize the matrix. For example, the following creates a new matrix with a 45 degree rotation.

var m = Ti.UI.create2DMatrix({
    rotate: 45
});

If you pass no arguments, create2DMatrix returns an identity matrix.

Examples

Apply a 2D Matrix to a Label

The following uses a 2D matrix to translate a label in the y direction.

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

var label = Ti.UI.createLabel({
  font:{fontSize:50},
  text:'Titanium',
  textAlign:'center',
  top: 100
});
win.add(label);

var button = Ti.UI.createButton({
  title:'Animate',
  bottom:20,
  width:200, height:40
});
win.add(button);

button.addEventListener('click', function(){
  var t1 = Ti.UI.create2DMatrix();
  t1 = t1.translate(0, 300);
  var a1 = Ti.UI.createAnimation();
  a1.transform = t1;
  a1.duration = 800;
  label.animate(a1);
});
win.open();
  • 0.9
  • 0.9
  • 0.9
Defined By

Properties

Titanium.UI.2DMatrix
a : Number

The entry at position [1,1] in the matrix.

The entry at position [1,1] in the matrix.

  • 0.9
  • 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.2DMatrix
b : Number

The entry at position [1,2] in the matrix.

The entry at position [1,2] in the matrix.

  • 0.9
  • 0.9
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.2DMatrix
c : Number

The entry at position [2,1] in the matrix.

The entry at position [2,1] in the matrix.

  • 0.9
  • 0.9
Titanium.UI.2DMatrix
d : Number

The entry at position [2,2] in the matrix.

The entry at position [2,2] in the matrix.

  • 0.9
  • 0.9

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.2DMatrix
tx : Number

The entry at position [3,1] in the matrix.

The entry at position [3,1] in the matrix.

  • 0.9
  • 0.9
Titanium.UI.2DMatrix
ty : Number

The entry at position [3,2] in the matrix.

The entry at position [3,2] in the matrix.

  • 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.2DMatrix
( ) : Number
Gets the value of the a property. ...

Gets the value of the a property.

  • 0.9
  • 0.9

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
Titanium.UI.2DMatrix
( ) : Number
Gets the value of the b property. ...

Gets the value of the b property.

  • 0.9
  • 0.9

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.2DMatrix
( ) : Number
Gets the value of the c property. ...

Gets the value of the c property.

  • 0.9
  • 0.9

Returns

  • Number
Titanium.UI.2DMatrix
( ) : Number
Gets the value of the d property. ...

Gets the value of the d property.

  • 0.9
  • 0.9

Returns

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

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.UI.2DMatrix
( ) : Number
Gets the value of the tx property. ...

Gets the value of the tx property.

  • 0.9
  • 0.9

Returns

  • Number
Titanium.UI.2DMatrix
( ) : Number
Gets the value of the ty property. ...

Gets the value of the ty property.

  • 0.9
  • 0.9

Returns

  • Number
Titanium.UI.2DMatrix
( ) : Titanium.UI.2DMatrix
Returns a matrix constructed by inverting this matrix. ...

Returns a matrix constructed by inverting this matrix.

Returns

Titanium.UI.2DMatrix
( t2 ) : Titanium.UI.2DMatrix
Returns a matrix constructed by combining two existing matrices. ...

Returns a matrix constructed by combining two existing matrices.

The argument, t2 is concatenated to the matrix instance against which the function is invoked. The resulting matrix is the result of multiplying this matrix by t2. You might perform several multiplications in order to create a single matrix that contains the cumulative effects of several transformations.

Note that matrix operations are not commutative -- the order in which you concatenate matrices is important. That is, the result of multiplying matrix t1 by matrix t2 does not necessarily equal the result of multiplying matrix t2 by matrix t1.

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.2DMatrix
( angle, [toAngle] ) : Titanium.UI.2DMatrix
Returns a matrix constructed by rotating this matrix. ...

Returns a matrix constructed by rotating this matrix.

There are two distinct versions of this method, depending on whether one argument or two are specified.

  • rotate(angle). The standard rotate method.
  • rotate(fromAngle, toAngle). Android only. Used for specifying rotation animations.

In both cases, a positive value specifies clockwise rotation and a negative value specifies counter-clockwise rotation.

Details for each version are discussed below.

rotate(angle)

Returns a matrix constructed by rotating this matrix.

Note that the resulting matrix only expresses the final transformation, not the direction of the rotation. For example, the matrix produced by m1.rotate(-10) is identical to the matrix produced by m1.rotate(350) and m1.rotate(710).

Note that if you specify a rotation matrix as the transform property of an animation, the animation animates the view from its current rotation to the rotation represented by the matrix by its shortest path. So to rotate a view in a complete circle, the easiest method is to chain together three animations, rotating 120 degrees each time.

For the purposes of animation, it should be noted that the rotation angle is normalized to the range -180 <= angle < 180. In other words, an angle of 180 degrees is normalized to -180. This makes no difference except when determining which direction an animation rotates. 179 degrees rotates rotate clockwise, but 180 degrees is normalized to -180, so rotates counter-clockwise.

rotate(angle, toAngle) -- Android Only

This is an Android-specific method used for creating rotation animations. Returns a 2DMatrix object that represents a rotation from angle to toAngle.

Angles are specified in degrees. Positive values represent clockwise rotation, and negative values represent counter-clockwise rotation. Values are not normalized, so for example an angle of 720 degrees represents two complete clockwise revolutions.

The resulting object cannot be expressed as an affine transform, but can be used with the Titanium.UI.Animation.transform property to specify a rotation animation.

Parameters

  • angle : Number

    Angle to rotate to, in degrees. On Android, if angleTo is specified, this specifies the starting angle for a rotation animation.

  • toAngle : Number (optional)

    Ending angle for a rotation animation, in degrees. Android only.

Returns

Titanium.UI.2DMatrix
( sx, sy, [toSx], [toSy] ) : Titanium.UI.2DMatrix
Returns a 2DMatrix object that specifies a scaling animation from one scale to another. ...

Returns a 2DMatrix object that specifies a scaling animation from one scale to another.

There are two distinct versions of this method, depending on whether two arguments or four are specified.

  • scale(sx, sy). The standard scale method.
  • scale(fromSx, fromSy, toSx, toSy). Android only. Used for specifying a scaling animation from one size to another.

scale(sx, sy)

Returns a matrix constructed by applying a scale transform to this matrix. Scaling the current matrix by sx along the X axis and by sy along the Y axis.

scale(sx, sy, toSx, toSy) -- Android Only

This Android-specific method returns a 2DMatrix object that can be used to create a scaling animation from one scale factor to another scale factor.

The resulting object cannot be expressed as an affine transform, but can be used with the Titanium.UI.Animation.transform property to specify a scaling animation.

Parameters

  • sx : Number

    Horizontal scaling factor. If toSx and toSy are specified, this specifies the starting horizontal scaling factor, at the beginning of an animation.

  • sy : Number

    Vertical scaling factor. If toSx and toSy are specified, this specifies the starting vertical scaling factor, at the beginning of an animation.

  • toSx : Number (optional)

    Ending horizontal scaling factor, at the end of an animation. If specified, toSy must be specified as well. Android only.

  • toSy : Number (optional)

    Ending vertical scaling factor, at the end of an animation. If specified, toSx must be specified as well. Android only.

Returns

Titanium.UI.2DMatrix
( a )
Sets the value of the a property. ...

Sets the value of the a property.

  • 0.9
  • 0.9

Parameters

  • a : Number

    New value for the property.

Returns

  • void
Titanium.UI.2DMatrix
( b )
Sets the value of the b property. ...

Sets the value of the b property.

  • 0.9
  • 0.9

Parameters

  • b : 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.2DMatrix
( c )
Sets the value of the c property. ...

Sets the value of the c property.

  • 0.9
  • 0.9

Parameters

  • c : Number

    New value for the property.

Returns

  • void
Titanium.UI.2DMatrix
( d )
Sets the value of the d property. ...

Sets the value of the d property.

  • 0.9
  • 0.9

Parameters

  • d : 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.2DMatrix
( tx )
Sets the value of the tx property. ...

Sets the value of the tx property.

  • 0.9
  • 0.9

Parameters

  • tx : Number

    New value for the property.

Returns

  • void
Titanium.UI.2DMatrix
( ty )
Sets the value of the ty property. ...

Sets the value of the ty property.

  • 0.9
  • 0.9

Parameters

  • ty : Number

    New value for the property.

Returns

  • void
Titanium.UI.2DMatrix
( tx, ty ) : Titanium.UI.2DMatrix
Returns a matrix constructed by applying a translation transform to this matrix. ...

Returns a matrix constructed by applying a translation transform to this matrix.

Parameters

  • tx : Number

    Horizontal component of the translation.

  • ty : Number

    Vertical component of the translation.

Returns