# Titanium.UI.iOS.AnchorAttachmentBehavior

> Dynamic behavior to support connections between an anchor point and an item.

- Source: https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.UI.iOS.AnchorAttachmentBehavior
- Titanium SDK version: 12.5.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

An anchor attachment behavior creates a dynamic connection between an anchor point and an item.
To define an anchor attachment behavior:

  1. Use the [Titanium.UI.iOS.createAnchorAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.md#createAnchorAttachmentBehavior) method to create a behavior.
  2. Set the [anchor](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AnchorAttachmentBehavior.md#anchor) and
     [item](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AnchorAttachmentBehavior.md#item) properties.
  3. Add the behavior to the [Animator object](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.Animator.md).

To create a dynamic connection between two items, use [Titanium.UI.iOS.ViewAttachmentBehavior](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.ViewAttachmentBehavior.md).

## Example: Simple Example

The following example creates a red block and anchors it to a point near the top-center of
the window.  Using a gravitational force, the red block swings like a pendulum.

<img src="./anchorattachment.gif" height="200" 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});

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

var WIDTH = Ti.Platform.displayCaps.platformWidth;

// Anchor the red block to a point near the top-center
var anchor = Ti.UI.iOS.createAnchorAttachmentBehavior({
    anchor: {x: WIDTH/2, y: 10},
    item: redBlock
});
animator.addBehavior(anchor);

// Simulate Earth's gravity to allow the pendulum to swing
var gravity = Ti.UI.iOS.createGravityBehavior({
    gravityDirection: {x: 0.0, y: 1.0}
});
gravity.addItem(redBlock);
animator.addBehavior(gravity);

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

win.add(redBlock);
win.open();
```

## Properties

### anchor

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

Anchor point for the attachment behavior relative to the animator's coordinate system.

### damping

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

Amount of damping to apply to the attachment behavior.

### distance

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

Distance, in points, between the two attachment points.

### frequency

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

Frequency of oscillation for the behavior.

### item

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

Item to connect to use the attachment behavior.

### offset

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

Offset from the center point of the item for the attachment.

## Inherited members

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

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.5.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`.

