# Titanium.UI.iOS.SnapBehavior

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

- Source: https://titaniumsdk.com/docs/sdk/12.7.0/Titanium.UI.iOS.SnapBehavior
- Titanium SDK version: 12.7.0
- Kind: proxy
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0
- Extends: Titanium.Proxy
- Inheritance: Titanium.Proxy

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](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.md#createSnapBehavior) method to create the behavior.
  2. Set the [item](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.SnapBehavior.md#item) and
     [snapPoint](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.SnapBehavior.md#snapPoint) properties.
  3. Add the behavior to an [Animator object](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.Animator.md).

## Example: Simple Example

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

<img src="./snapbehavior.gif" height="455" style="border:1px solid black"/>

``` js
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

### damping

- Type: Number
- Platforms: iPhone, iPad, macOS
- Default: `0.5`

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.

### item

- Type: Titanium.UI.View
- Platforms: iPhone, iPad, macOS

Item to add to this behavior.

### snapPoint

- Type: Point
- Platforms: iPhone, iPad, macOS
- Default: `(0,0)`

Specifies the point to snap to.

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

## Inherited members

6 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.7.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `removeEventListener`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

