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

Commit 625ffe1

Browse files
author
Jeff Verkoeyen
committed
Update docs.
1 parent 4f81655 commit 625ffe1

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

MotionAnimator.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "MotionAnimator"
3-
s.summary = "Motion Animator"
3+
s.summary = "A Motion Animator creates performant, interruptible animations from motion specs."
44
s.version = "1.0.0"
55
s.authors = "The Material Motion Authors"
66
s.license = "Apache 2.0"

README.md

+97-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
# Motion Animator
22

3+
> A Motion Animator creates performant, interruptible animations from motion specs.
4+
35
[![Build Status](https://travis-ci.org/material-motion/motion-animator-objc.svg?branch=develop)](https://travis-ci.org/material-motion/motion-animator-objc)
46
[![codecov](https://codecov.io/gh/material-motion/motion-animator-objc/branch/develop/graph/badge.svg)](https://codecov.io/gh/material-motion/motion-animator-objc)
5-
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/motion-animator.svg)](https://cocoapods.org/pods/motion-animator)
6-
[![Platform](https://img.shields.io/cocoapods/p/motion-animator.svg)](http://cocoadocs.org/docsets/motion-animator)
7-
[![Docs](https://img.shields.io/cocoapods/metrics/doc-percent/motion-animator.svg)](http://cocoadocs.org/docsets/motion-animator)
7+
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/MotionAnimator.svg)](https://cocoapods.org/pods/MotionAnimator)
8+
[![Platform](https://img.shields.io/cocoapods/p/MotionAnimator.svg)](http://cocoadocs.org/docsets/MotionAnimator)
9+
[![Docs](https://img.shields.io/cocoapods/metrics/doc-percent/MotionAnimator.svg)](http://cocoadocs.org/docsets/MotionAnimator)
10+
11+
This library turns [Motion Interchange](https://github.com/material-motion/motion-interchange-objc)
12+
data structures into performant Core Animation animations using a lightweight animator object.
13+
14+
<img src="assets/calendar-chip.gif" />
15+
16+
In the above example we're animating the expansion and collapse of a calendar event using the
17+
following motion specification:
18+
19+
```objc
20+
struct CalendarChipTiming {
21+
MDMMotionTiming chipWidth;
22+
MDMMotionTiming chipHeight;
23+
MDMMotionTiming chipY;
24+
25+
MDMMotionTiming chipContentOpacity;
26+
MDMMotionTiming headerContentOpacity;
27+
28+
MDMMotionTiming navigationBarY;
29+
};
30+
typedef struct CalendarChipTiming CalendarChipTiming;
31+
32+
struct CalendarChipMotionSpec {
33+
CalendarChipTiming expansion;
34+
CalendarChipTiming collapse;
35+
};
36+
typedef struct CalendarChipMotionSpec CalendarChipMotionSpec;
37+
38+
FOUNDATION_EXTERN struct CalendarChipMotionSpec CalendarChipSpec;
39+
```
40+
41+
In our application logic, we first determine which motion timing to use and then we create an
42+
instance of `MDMMotionAnimator`. The animator allows us to create animations with the given
43+
motion timing.
44+
45+
```objc
46+
CalendarChipTiming timing = _expanded ? CalendarChipSpec.expansion : CalendarChipSpec.collapse;
47+
48+
MDMMotionAnimator *animator = [[MDMMotionAnimator alloc] init];
49+
animator.shouldReverseValues = !_expanded;
50+
51+
[animator animateWithTiming:timing.chipHeight
52+
toLayer:chipView.layer
53+
withValues:@[ @(chipFrame.size.height), @(headerFrame.size.height) ]
54+
keyPath:MDMKeyPathHeight];
55+
...
56+
```
857
958
## Installation
1059
@@ -19,7 +68,7 @@
1968
2069
Add `motion-animator` to your `Podfile`:
2170
22-
pod 'motion-animator'
71+
pod 'MotionAnimator'
2372
2473
Then run the following command:
2574
@@ -29,7 +78,7 @@ Then run the following command:
2978
3079
Import the framework:
3180
32-
@import motion-animator;
81+
@import MotionAnimator;
3382
3483
You will now have access to all of the APIs.
3584
@@ -41,16 +90,56 @@ commands:
4190
git clone https://github.com/material-motion/motion-animator-objc.git
4291
cd motion-animator-objc
4392
pod install
44-
open motion-animator.xcworkspace
93+
open MotionAnimator.xcworkspace
4594
4695
## Guides
4796
4897
1. [Architecture](#architecture)
49-
2. [How to ...](#how-to-...)
98+
2. [How to animate a transition](#how-to-animate-a-transition)
99+
3. [How to animate an interruptible transition](#how-to-animate-an-interruptible-transition)
50100
51101
### Architecture
52102
53-
### How to ...
103+
`MDMMotionAnimator` is the primary API provided by this library and its external API is fairly
104+
straight forward. Once an instance is created, you can configure its behavior by modifying its
105+
properties. When you're ready to add an animation to a CALayer instance, simply call one of the
106+
`animate` method variants and an animation will instantly be added to the layer.
107+
108+
This library depends on [MotionInterchange](https://github.com/material-motion/motion-interchange-objc)
109+
in order to represent motion timing in a consistent fashion.
110+
111+
### How to animate a transition
112+
113+
> This guide assumes that you are animating a two state bi-directional transition.
114+
115+
Start by creating an `MDMMotionAnimator` instance.
116+
117+
```objc
118+
MDMMotionAnimator *animator = [[MDMMotionAnimator alloc] init];
119+
```
120+
121+
When we describe our transition we'll describe it as though we're moving forward and take advantage
122+
of the `shouldReverseValues` property on our animator to handle the reverse direction.
123+
124+
```objc
125+
animator.shouldReverseValues = isTransitionReversed;
126+
```
127+
128+
To animate a property on a view, we invoke the `animate` method. We must provide a timing, values,
129+
and a key path:
130+
131+
```objc
132+
[animator animateWithTiming:timing
133+
toLayer:view.layer
134+
withValues:@[ @(collapsedHeight), @(expandedHeight) ]
135+
keyPath:MDMKeyPathHeight];
136+
```
137+
138+
### How to animate an interruptible transition
139+
140+
`MDMMotionAnimator` is configured by default to generate interruptible animations using Core
141+
Animation's additive animation APIs. You can simply re-execute the `animate` calls when your
142+
transition's direction changes and the animator will add new animations for the updated direction.
54143
55144
## Contributing
56145

assets/calendar-chip.gif

185 KB
Loading

0 commit comments

Comments
 (0)