You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 3, 2020. It is now read-only.
Pop is an extensible animation engine for iOS, tvOS, and OS X. In addition to basic static animations, it supports spring and decay dynamic animations, making it useful for building realistic, physics-based interactions. The API allows quick integration with existing Objective-C codebases and enables the animation of any property on any object. It's a mature and well-tested framework that drives all the animations and transitions in [Paper](http://www.facebook.com/paper).
3
+
Pop is an extensible animation engine for iOS, tvOS, and OS X. In addition to basic static animations, it supports spring and decay dynamic animations, making it useful for building realistic, physics-based interactions. The API allows quick integration with existing Objective-C or Swift codebases and enables the animation of any property on any object. It's a mature and well-tested framework that drives all the animations and transitions in [Paper](http://www.facebook.com/paper).
To stop an animation, remove it from the object referencing the key specified on start:
58
76
77
+
#### Objective-C
78
+
59
79
```objective-c
60
80
[layer pop_removeAnimationForKey:@"myKey"];
61
81
```
62
82
83
+
#### Swift
84
+
85
+
```swift
86
+
layer.pop_removeAnimation(forKey: "myKey")
87
+
```
88
+
63
89
The key can also be used to query for the existence of an animation. Updating the toValue of a running animation can provide the most seamless way to change course:
64
90
91
+
#### Objective-C
92
+
65
93
```objective-c
66
94
anim = [layer pop_animationForKey:@"myKey"];
67
95
if (anim) {
@@ -73,6 +101,18 @@ if (anim) {
73
101
}
74
102
```
75
103
104
+
#### Swift
105
+
106
+
```swift
107
+
if let anim = layer.pop_animation(forKey: "myKey") as? POPSpringAnimation {
108
+
/* update to value to new destination */
109
+
anim.toValue = 42.0
110
+
} else {
111
+
/* create and start a new animation */
112
+
....
113
+
}
114
+
```
115
+
76
116
While a layer was used in the above examples, the Pop interface is implemented as a category addition on NSObject. Any NSObject or subclass can be animated.
77
117
78
118
### Types
@@ -81,41 +121,92 @@ There are four concrete animation types: spring, decay, basic and custom.
81
121
82
122
Spring animations can be used to give objects a delightful bounce. In this example, we use a spring animation to animate a layer's bounds from its current value to (0, 0, 400, 400):
Decay animations can be used to gradually slow an object to a halt. In this example, we decay a layer's positionX from it's current value and velocity 1000pts per second:
if let anim = POPDecayAnimation(propertyNamed: kPOPLayerPositionX) {
155
+
anim.velocity = 1000.0
156
+
layer.pop_add(anim, forKey: "slide")
157
+
}
158
+
```
159
+
97
160
Basic animations can be used to interpolate values over a specified time period. To use an ease-in ease-out animation to animate a view's alpha from 0.0 to 1.0 over the default duration:
`POPCustomAnimation` makes creating custom animations and transitions easier by handling CADisplayLink and associated time-step management. See header for more details.
106
184
107
185
108
186
### Properties
109
187
110
188
The property animated is specified by the `POPAnimatableProperty` class. In this example we create a spring animation and explicitly set the animatable property corresponding to `-[CALayer bounds]`:
if let property = POPAnimatableProperty.property(withName: kPOPLayerBounds) as? POPAnimatableProperty {
202
+
anim.property = property
203
+
}
204
+
```
205
+
117
206
The framework provides many common layer and view animatable properties out of box. You can animate a custom property by creating a new instance of the class. In this example, we declare a custom volume property:
if let prop = POPAnimatableProperty.property(withName: "com.foo.radio.volume", initializer: { prop in
231
+
guard let prop = prop else {
232
+
return
233
+
}
234
+
// read value
235
+
prop.readBlock = { obj, values in
236
+
guard let obj = obj as? Volumeable, let values = values else {
237
+
return
238
+
}
239
+
240
+
values[0] = obj.volume
241
+
}
242
+
// write value
243
+
prop.writeBlock = { obj, values in
244
+
guard var obj = obj as? Volumeable, let values = values else {
245
+
return
246
+
}
247
+
248
+
obj.volume = values[0]
249
+
}
250
+
// dynamics threshold
251
+
prop.threshold = 0.01
252
+
}) as? POPAnimatableProperty {
253
+
anim.property = prop
254
+
}
255
+
```
256
+
136
257
For a complete listing of provided animatable properties, as well more information on declaring custom properties see `POPAnimatableProperty.h`.
137
258
138
259
@@ -142,18 +263,37 @@ Here are a few tips when debugging. Pop obeys the Simulator's Toggle Slow Animat
142
263
143
264
Consider naming your animations. This will allow you to more easily identify them when referencing them, either via logging or in the debugger:
144
265
266
+
#### Objective-C
267
+
145
268
```objective-c
146
269
anim.name = @"springOpen";
147
270
```
148
271
272
+
#### Swift
273
+
274
+
```swift
275
+
anim.name="springOpen"
276
+
```
277
+
149
278
Each animation comes with an associated tracer. The tracer allows you to record all animation-related events, in a fast and efficient manner, allowing you to query and analyze them after animation completion. The below example starts the tracer and configures it to log all events on animation completion:
0 commit comments