Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,103 @@ animator.animate(with: traits,
keyPath: .y)
```

## API snippets

### Implicit animations

```swift
MotionAnimator.animate(withDuration: <#T##TimeInterval#>) {
<#code#>
}
```

```swift
MotionAnimator.animate(withDuration: <#T##TimeInterval#>,
delay: <#T##TimeInterval#>,
options: <#T##UIViewAnimationOptions#>,
animations: {
<#code#>
})
```

### Explicit animations

```swift
let traits = MDMAnimationTraits(delay: <#T##TimeInterval#>,
duration: <#T##TimeInterval#>,
animationCurve: <#T##UIViewAnimationCurve#>)
let animator = MotionAnimator()
animator.animate(with: <#T##MDMAnimationTraits#>,
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
layer: <#T##CALayer#>,
keyPath: <#T##AnimatableKeyPath#>)
```

### Animating transitions

```swift
let animator = MotionAnimator()
animator.shouldReverseValues = transition.direction == .backwards

let traits = MDMAnimationTraits(delay: <#T##TimeInterval#>,
duration: <#T##TimeInterval#>,
animationCurve: <#T##UIViewAnimationCurve#>)
animator.animate(with: <#T##MDMAnimationTraits#>,
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
layer: <#T##CALayer#>,
keyPath: <#T##AnimatableKeyPath#>)
```

### Creating motion specifications

```swift
class MotionSpec {
static let chipWidth = MDMAnimationTraits(delay: 0.000, duration: 0.350)
static let chipHeight = MDMAnimationTraits(delay: 0.000, duration: 0.500)
}

let animator = MotionAnimator()
animator.shouldReverseValues = transition.direction == .backwards

animator.animate(with: MotionSpec.chipWidth,
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
layer: <#T##CALayer#>,
keyPath: <#T##AnimatableKeyPath#>)
animator.animate(with: MotionSpec.chipHeight,
between: [<#T##[From (Any)]#>, <#T##[To (Any)]#>],
layer: <#T##CALayer#>,
keyPath: <#T##AnimatableKeyPath#>)
```

### Animating from the current state

```swift
// Will animate any non-additive animations from their current presentation layer value
animator.beginFromCurrentState = true
```

### Debugging animations

```swift
animator.addCoreAnimationTracer { layer, animation in
print(animation.debugDescription)
}
```

### Stopping animations in reaction to a gesture recognizer

```swift
if gesture.state == .began {
animator.stopAllAnimations()
}
```

### Removing all animations

```swift
animator.removeAllAnimations()
```

## Example apps/unit tests

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