forked from tidev/titanium-sdk
/
Animation.yml
308 lines (253 loc) Β· 12.1 KB
/
Animation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
---
name: Titanium.UI.Animation
summary: The `Animation` object defines an animation that can be applied to a view.
description: |
An animation object describes the properties of an animation. At its most basic, an animation
object represents a single-phase animation with an end state and a duration.
When [animate](Titanium.UI.View.animate) is called on a [View](Titanium.UI.View), the view is
animated from its current state to the state described by the animation object. The properties
that can be animated include the view's position, size, colors, transformation matrix and opacity.
Animations can be set to reverse themselves automatically on completion, and to repeat a given
number of times. For more complicated effects, multiple animations can be combined in sequence,
starting one animation when the previous animation completes.
Use the <Titanium.UI.createAnimation> method to create an animation object.
Note that when you animate a view's size or position, the actual layout properties (such as
`top`, `left`, `width`, `height`) are not changed by the animation. See the description of the
[animate](Titanium.UI.View.animate) method for more information.
#### iOS Platform Notes
iOS supports both 2D and 3D matrix transformations in animations.
In iOS, you can also specify an animation curve or *easing function* to control the pace of the
animation. To use an easing function, set the animation's `curve` property to one of the
`ANIMATION_CURVE` constants defined in <Titanium.UI>. For example,
[ANIMATION_CURVE_EASE_IN](Titanium.UI.ANIMATION_CURVE_EASE_IN) specifies an animation that
starts slowly and then speeds up.
Finally, iOS also supports *transitions* between windows or views. You can create a transition
by creating an animation object and setting the `view` property to the view you want to
transition to. The `transition` property specifies the transition effect to apply. Use one of
the transition style constants defined in <Titanium.UI.iPhone.AnimationStyle>.
#### Android Platform Notes
Android supports 2D matrix transformations. Note that the
[2DMatrix.rotate](Titanium.UI.2DMatrix.rotate) method operates differently on Android. Called
with a single argument, it rotates from zero to the specified angle. That is, it ignores any
existing rotation. Called with two arguments, it interprets the first argument as a "from"
angle and the second argument as a "to" angle.
Android doesn't support any animation curves or easing functions. Animations always interpolate
linearly between the start state and the end state.
extends: Titanium.Proxy
since: "0.9"
platforms: [android, iphone, ipad, mobileweb]
events:
- name: complete
summary: Fired when the animation completes.
- name: start
summary: Fired when the animation starts.
properties:
- name: anchorPoint
summary: Coordinate of the view about which to pivot an animation.
description: |
Used on Android only. For iOS, use <Titanium.UI.View.anchorPoint>.
Anchor point is specified as a fraction of the view's size. For example, `{0, 0}` is at
the view's top-left corner, `{0.5, 0.5}` at its center and `{1, 1}` at its bottom-right
corner.
See the "Using an anchorPoint" example for a demonstration.
type: Point
platforms: [android]
- name: autoreverse
summary: Specifies if the animation should be replayed in reverse upon completion.
type: Boolean
default: false
- name: backgroundColor
summary: |
Value of the `backgroundColor` property at the end of the animation, as a color name
or hex triplet.
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
type: String
platforms: [android, iphone, ipad, mobileweb]
- name: bottom
summary: Value of the `bottom` property at the end of the animation.
type: Number
- name: center
summary: Value of the `center` property at the end of the animation.
type: Object
- name: color
summary: |
Value of the `color` property at the end of the animation, as a color name or hex triplet.
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
type: String
platforms: [iphone, ipad, mobileweb]
- name: curve
summary: Animation curve or easing function to apply to the animation.
description: |
Specify one of the animation constants,
<Titanium.UI.ANIMATION_CURVE_EASE_IN>,
<Titanium.UI.ANIMATION_CURVE_EASE_IN_OUT>,
<Titanium.UI.ANIMATION_CURVE_EASE_OUT>,
or <Titanium.UI.ANIMATION_CURVE_LINEAR>.
type: Number
platforms: [iphone, ipad, mobileweb]
- name: delay
summary: Delay, in milliseconds before starting the animation.
type: Number
- name: duration
summary: Duration of the animation, in milliseconds.
type: Number
- name: height
summary: Value of the `height` property at the end of the animation.
type: Number
- name: left
summary: Value of the `left` property at the end of the animation.
type: Number
- name: opacity
summary: Value of the `opacity` property at the end of the animation.
type: Number
- name: opaque
summary: Value of the `opaque` property at the end of the animation.
type: Boolean
platforms: [iphone, ipad]
- name: repeat
summary: Number of times the animation should be performed.
description: |
If `autoreverse` is `true`, then one repeat of the animation consists of the animation
being played once forward, and once backward.
type: Number
default: 1 (no repeat)
- name: right
summary: Value of the `right` property at the end of the animation.
type: Number
- name: top
summary: Value of the `top` property at the end of the animation.
type: Number
- name: transform
summary: Animate the view from its current tranform to the specified transform.
description: |
Over the course of the animation, the view interpolates from its current transform to the
specified transform.
3D transforms are only supported on iOS.
type: [Titanium.UI.2DMatrix, Titanium.UI.iOS.3DMatrix]
- name: transition
summary: Transition type to use during a transition animation.
description: |
One of the activity indicator style constants
<Titanium.UI.iPhone.AnimationStyle.CURL_DOWN>,
<Titanium.UI.iPhone.AnimationStyle.CURL_UP>,
<Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT>,
<Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT>,
or <Titanium.UI.iPhone.AnimationStyle.NONE>.
#### NOTE:
The view being transitioned **should NOT** already be a child of another view or
of the animating view.The animation inf effect replaces current view from the
view heirarchy and adds the new view to it.
type: Number
platforms: [iphone, ipad]
- name: visible
summary: Value of the `visible` property at the end of the animation.
type: Boolean
platforms: [iphone, ipad, mobileweb]
- name: width
summary: Value of the `width` property at the end of the animation.
type: Number
- name: zIndex
summary: Value of the `zIndex` property at the end of the animation.
description: Refer to <Titanium.UI.View.zIndex> for an explanation of z-index.
type: Number
platforms: [iphone, ipad, mobileweb]
examples:
- title: Simple Animation Applied to a View
example: |
Create a simple animation and apply it to the view. In this example, the view will animate
from red to black to orange over 2 seconds.
var view = Titanium.UI.createView({
backgroundColor:'red'
});
var animation = Titanium.UI.createAnimation();
animation.backgroundColor = 'black';
animation.duration = 1000;
var animationHandler = function() {
animation.removeEventListener('complete',animationHandler);
animation.backgroundColor = 'orange';
view.animate(animation);
};
animation.addEventListener('complete',animationHandler);
view.animate(animation);
- title: Animation Using Matrix Transforms
example: |
The following example uses a transformation matrix to animate
a view when the view is clicked. The animation rotates and scales
the view, then returns it to its original size and position. The
entire animation is repeated three times.
var box = Ti.UI.createView({
backgroundColor : 'red',
height : '100',
width : '100'
});
win.add(box);
box.addEventListener('click', function() {
var matrix = Ti.UI.create2DMatrix()
matrix = matrix.rotate(180);
matrix = matrix.scale(2, 2);
var a = Ti.UI.createAnimation({
transform : matrix,
duration : 2000,
autoreverse : true,
repeat : 3
});
box.animate(a);
});
- title: Using an anchorPoint (Android and iOS)
example: |
Create a button and a blue square view. For each click of the button, apply a 90 degree
rotation animation pivoted at one of a series of anchor points. In particular, note that
an anchor point is configured using the <Titanium.UI.Animation.anchorPoint> property for
Android and the <Titanium.UI.View.anchorPoint> property for iOS.
var animationType = [
{ name: 'Top Left', anchorPoint: {x:0, y:0} },
{ name: 'Top Right', anchorPoint: {x:1, y:0} },
{ name: 'Bottom Left', anchorPoint: {x:0, y:1} },
{ name: 'Bottom Right', anchorPoint: {x:1, y:1} },
{ name: 'Center', anchorPoint: {x:0.5, y:0.5} }
];
var animationTypeLength = animationType.length;
var animationCount = 0;
var animationTypePointer = 0;
var t = Ti.UI.create2DMatrix();
t = t.rotate(90);
// animation properties
var a = {
transform: t,
duration: 2000,
autoreverse: true
};
Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow();
var view = Ti.UI.createView({
backgroundColor:'#336699',
width:100, height:100
});
win.add(view);
var button = Ti.UI.createButton({
title:'Animate ' + animationType[animationTypePointer].name,
height: (Ti.UI.Android) ? 80 : 40,
width: (Ti.UI.Android) ? 300 : 200,
top:30
});
win.add(button);
function updateButton(name){
button.title = 'Animate ' + name;
}
button.addEventListener('click', function(){
// set new anchorPoint on animation for Android
a.anchorPoint = animationType[animationTypePointer].anchorPoint;
// set new anchorPoint on view for iOS
view.anchorPoint = animationType[animationTypePointer].anchorPoint;
animationCount++;
// determine position of next object in animationType array or return to first item
// using modulus operator
animationTypePointer = animationCount % animationTypeLength;
// animate view, followed by callback to set next button title
view.animate(a, function(){
updateButton(animationType[animationTypePointer].name);
});
});
win.open();