Skip to content
Titanium SDK
Version13.4.0

You are reading 13.4.0. See this page in 13.4.1.

Titanium.UI.iOS.SnapBehavior

proxyiPhoneiPadmacOSsince iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0

Extends Titanium.Proxy

Dynamic behavior defining an item's movement to a specific point.

A snap behavior specifies how an item moves towards a specified point with a spring-like effect, ending with an oscillation.

  1. Use the Titanium.UI.iOS.createSnapBehavior method to create the behavior.
  2. Set the item and snapPoint properties.
  3. Add the behavior to an Animator object.

Examples

Simple Example

The following example snaps the block to the location of a click on the window.

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

// Snap to the top-left corner when the app starts
var snap = Ti.UI.iOS.createSnapBehavior({
    item: block,
    snapPoint: {x: 0, y: 0},
});
animator.addBehavior(snap);

// Snap the block to the point of the click event
win.addEventListener('click', function(e){
    snap.snapPoint = {x: e.x, y: e.y};
    snap.damping = Math.random();
});

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

win.add(block);
win.open();

Properties 5

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

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

Default: true

damping

Number

Specifies the amount of oscillation during the conclusion of the snap.

A value of 0.0 indicates minimum oscillation, while 1.0 indicates maximum oscillation.

Default: 0.5

Specifies the point to snap to.

The coordinate system depends on the animator's reference view.

Default: (0,0)

Methods 4

Inherited from Titanium.Proxy

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

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

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

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

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

Inherited from Titanium.Proxy

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

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

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

4 fields
bubbles Boolean

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

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.