Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 823e0ff

Browse files
authoredDec 19, 2017
Add API snippets section. (#106)
1 parent d53f753 commit 823e0ff

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
 

‎README.md

+97
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,103 @@ animator.animate(with: traits,
160160
keyPath: .y)
161161
```
162162

163+
## API snippets
164+
165+
### Implicit animations
166+
167+
```swift
168+
MotionAnimator.animate(withDuration: <#T##TimeInterval#>) {
169+
<#code#>
170+
}
171+
```
172+
173+
```swift
174+
MotionAnimator.animate(withDuration: <#T##TimeInterval#>,
175+
delay: <#T##TimeInterval#>,
176+
options: <#T##UIViewAnimationOptions#>,
177+
animations: {
178+
<#code#>
179+
})
180+
```
181+
182+
### Explicit animations
183+
184+
```swift
185+
let traits = MDMAnimationTraits(delay: <#T##TimeInterval#>,
186+
duration: <#T##TimeInterval#>,
187+
animationCurve: <#T##UIViewAnimationCurve#>)
188+
let animator = MotionAnimator()
189+
animator.animate(with: <#T##MDMAnimationTraits#>,
190+
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
191+
layer: <#T##CALayer#>,
192+
keyPath: <#T##AnimatableKeyPath#>)
193+
```
194+
195+
### Animating transitions
196+
197+
```swift
198+
let animator = MotionAnimator()
199+
animator.shouldReverseValues = transition.direction == .backwards
200+
201+
let traits = MDMAnimationTraits(delay: <#T##TimeInterval#>,
202+
duration: <#T##TimeInterval#>,
203+
animationCurve: <#T##UIViewAnimationCurve#>)
204+
animator.animate(with: <#T##MDMAnimationTraits#>,
205+
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
206+
layer: <#T##CALayer#>,
207+
keyPath: <#T##AnimatableKeyPath#>)
208+
```
209+
210+
### Creating motion specifications
211+
212+
```swift
213+
class MotionSpec {
214+
static let chipWidth = MDMAnimationTraits(delay: 0.000, duration: 0.350)
215+
static let chipHeight = MDMAnimationTraits(delay: 0.000, duration: 0.500)
216+
}
217+
218+
let animator = MotionAnimator()
219+
animator.shouldReverseValues = transition.direction == .backwards
220+
221+
animator.animate(with: MotionSpec.chipWidth,
222+
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
223+
layer: <#T##CALayer#>,
224+
keyPath: <#T##AnimatableKeyPath#>)
225+
animator.animate(with: MotionSpec.chipHeight,
226+
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
227+
layer: <#T##CALayer#>,
228+
keyPath: <#T##AnimatableKeyPath#>)
229+
```
230+
231+
### Animating from the current state
232+
233+
```swift
234+
// Will animate any non-additive animations from their current presentation layer value
235+
animator.beginFromCurrentState = true
236+
```
237+
238+
### Debugging animations
239+
240+
```swift
241+
animator.addCoreAnimationTracer { layer, animation in
242+
print(animation.debugDescription)
243+
}
244+
```
245+
246+
### Stopping animations in reaction to a gesture recognizer
247+
248+
```swift
249+
if gesture.state == .began {
250+
animator.stopAllAnimations()
251+
}
252+
```
253+
254+
### Removing all animations
255+
256+
```swift
257+
animator.removeAllAnimations()
258+
```
259+
163260
## Example apps/unit tests
164261

165262
Check out a local copy of the repo to access the Catalog application by running the following

0 commit comments

Comments
 (0)
This repository has been archived.