Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon_withrow committed Aug 2, 2017
1 parent ac25888 commit ad9303e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 28 deletions.
1 change: 1 addition & 0 deletions Example/lottie-ios/AnimationExplorerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ - (void)_loadAnimationNamed:(NSString *)named {
self.laAnimation = [LOTAnimationView animationNamed:named];
self.laAnimation.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:self.laAnimation];
[self.laAnimation setProgressWithFrame:@16];
[self.view setNeedsLayout];
}

Expand Down
75 changes: 57 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Lottie is a mobile library for Android and iOS that parses [Adobe After Effects]

For the first time, designers can create **and ship** beautiful animations without an engineer painstakingly recreating it by hand.
Since the animation is backed by JSON they are extremely small in size but can be large in complexity!
Animations can be played, resized, looped, sped up, slowed down, and even interactively scrubbed.

Animations can be played, resized, looped, sped up, slowed down, reversed, and even interactively scrubbed.
Lottie can play or loop just a portion of the animation as well, the possibilities are endless!
Animations can even be ***changed at runtime*** in various ways! Change the color, position or any keyframable value!
Lottie also supports native UIViewController Transitions out of the box!

Here is just a small sampling of the power of Lottie
Expand All @@ -21,7 +22,7 @@ Here is just a small sampling of the power of Lottie

## Using Lottie
Lottie supports iOS 8+ and MacOS 10.10+
Lottie animations can be loaded from bundled JSON or from a URL
Lottie animations can be loaded from any application Bundle or asynchronously from a URL

To bundle JSON just add it and any images that the animation requires to your target in xcode.

Expand Down Expand Up @@ -59,12 +60,30 @@ CGFloat progress = translation.y / self.view.bounds.size.height;
animationView.animationProgress = progress;
```

Or you can play just a portion of the animation:
```objective-c
[lottieAnimation playFromProgress:0.25 toProgress:0.5 withCompletion:^(BOOL animationFinished) {
// Do Something
}];
```
Want to mask arbitrary views to animation layers in a Lottie View?
Easy-peasy as long as you know the name of the layer from After Effects
```objective-c
UIView *snapshot = [self.view snapshotViewAfterScreenUpdates:YES];
[lottieAnimation addSubview:snapshot toLayerNamed:@"AfterEffectsLayerName"];
[lottieAnimation addSubview:snapshot toLayerNamed:@"AfterEffectsLayerName" applyTransform:NO];
```

Or how about moving a view with a part of the animation?
```objective-c
UIView *snapshot = [self.view snapshotViewAfterScreenUpdates:YES];
[lottieAnimation addSubview:snapshot toLayerNamed:@"AfterEffectsLayerName" applyTransform:YES];
```
Want to dynamically change the color of an animation?
```objective-c
[lottieAnimation setValue:[UIColor greenColor] forKeypath:@"Layer 1.Shape 1.Fill 1" atFrame:@0];
```

Lottie comes with a `UIViewController` animation-controller for making custom viewController transitions!
Expand All @@ -77,14 +96,16 @@ Lottie comes with a `UIViewController` animation-controller for making custom vi
sourceController:(UIViewController *)source {
LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition1"
fromLayerNamed:@"outLayer"
toLayerNamed:@"inLayer"];
toLayerNamed:@"inLayer"
applyAnimationTransform:NO];
return animationController;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition2"
fromLayerNamed:@"outLayer"
toLayerNamed:@"inLayer"];
toLayerNamed:@"inLayer"
applyAnimationTransform:NO];
return animationController;
}

Expand All @@ -109,6 +130,11 @@ animationView.play(completion: { finished in
Animation file name should be first added to your project. as for the above code sample, It won't work until you add an animation file called `hamburger.json`..
`let animationView = LOTAnimationView(name: "here_goes_your_json_file_name_without_.json")`

## MacOS support and Lottie View
Lottie also fully supports MacOS, so you can add animations to your awesome Mac App!
In the [Example Folder](Example/) you will find a Lottie Viewer Mac App. Build and run this app to preview Lottie animations straight from your desktop!
The app supports play, scrubbing, resizing, and most importantly you can drag and drop JSON files onto the app window to open any animation.

## Supported After Effects Features

### Keyframe Interpolation
Expand Down Expand Up @@ -137,7 +163,7 @@ Animation file name should be first added to your project. as for the above code

* Path
* Opacity
* Multiple Masks (additive)
* Multiple Masks (additive, subtractive and intersection)

### Track Mattes

Expand Down Expand Up @@ -166,6 +192,8 @@ Animation file name should be first added to your project. as for the above code
* Rectangle (All properties)
* Elipse (All properties)
* Multiple paths in one group
* Even-Odd winding paths
* Reverse Fill Rule

#### Stroke (shape layer)

Expand All @@ -175,7 +203,7 @@ Animation file name should be first added to your project. as for the above code
* Stroke Opacity
* Stroke Width
* Line Cap
* Dashes
* Dashes (Now Animated!)

#### Fill (shape layer)

Expand All @@ -192,6 +220,25 @@ Animation file name should be first added to your project. as for the above code
* Trim Paths End
* Trim Paths Offset

### Repeaters

---

* Supports repeater transforms
* Offset currently not supported.

### Gradients

---

* Support for Linear Gradients

### Polystar and Polygon

---

* Supported! Theres a known bug if the roundness is greater than 100 percent.

#### Layer Features

---
Expand All @@ -206,14 +253,12 @@ Animation file name should be first added to your project. as for the above code

## Currently Unsupported After Effects Features

* Even-Odd winding paths

* Merge Shapes
* Trim Shapes Individually feature of Trim Paths
* Expressions
* 3d Layer support
* Gradients
* Polystar shapes (Can convert to vector path as a workaround)
* Alpha inverted mask
* Radial Gradients


## Install Lottie
Expand Down Expand Up @@ -275,10 +320,4 @@ File github issues for anything that is unexpectedly broken. If an After Effects

## Roadmap (In no particular order)
- Add support for interactive animated transitions
- Add support for parenting programmatically added layers, moving/scaling
- Programmatically alter animations
- Animation Breakpoints/Seekpoints
- Gradients
- LOTAnimatedButton
- Repeater objects

12 changes: 6 additions & 6 deletions lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,15 @@ CGFloat LOT_CubicBezeirInterpolate(CGPoint P0, CGPoint P1, CGPoint P2, CGPoint P

CGFloat LOT_CubicLengthWithPrecision(CGPoint fromPoint, CGPoint toPoint, CGPoint controlPoint1, CGPoint controlPoint2, CGFloat iterations) {
CGFloat length = 0;

for (int i = 0; i < iterations; ++i) {
float s = i * (1.0 / iterations);
float t = s + (1.0 / iterations);
CGPoint previousPoint = fromPoint;
iterations = ceilf(iterations);
for (int i = 1; i <= iterations; ++i) {
float s = (float)i / iterations;

CGPoint p = LOT_PointInCubicCurve(fromPoint, controlPoint1, controlPoint2, toPoint, s);
CGPoint q = LOT_PointInCubicCurve(fromPoint, controlPoint1, controlPoint2, toPoint, t);

length += LOT_PointDistanceFromPoint(p, q);
length += LOT_PointDistanceFromPoint(previousPoint, p);
previousPoint = p;
}
return length;
}
Expand Down
21 changes: 17 additions & 4 deletions lottie-ios/Classes/Private/LOTAnimationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ - (void)_setupWithSceneModel:(LOTComposition *)model {
# pragma mark - External Methods

- (void)play {
[self playWithCompletion:nil];
[self playFromFrame:_sceneModel.startFrame toFrame:_sceneModel.endFrame withCompletion:nil];
}

- (void)playWithCompletion:(LOTAnimationCompletionBlock)completion {
[self playToFrame:_sceneModel.endFrame withCompletion:completion];
[self playFromFrame:_sceneModel.startFrame toFrame:_sceneModel.endFrame withCompletion:completion];
}

- (void)playToProgress:(CGFloat)progress withCompletion:(nullable LOTAnimationCompletionBlock)completion {
Expand Down Expand Up @@ -227,6 +227,18 @@ - (void)setLoopAnimation:(BOOL)loopAnimation {
_playAnimation.repeatCount = _loopAnimation ? HUGE_VALF : 1;
}

- (void)setProgressWithFrame:(nonnull NSNumber *)currentFrame {
[self _removeCurrentAnimationIfNecessary];
[self _callCompletionIfNecessary:NO];
CGFloat duration = _sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue;
_animationProgress = currentFrame.floatValue / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue);
[CATransaction begin];
[CATransaction setDisableActions:YES];
_compContainer.currentFrame = currentFrame;
[_compContainer setNeedsDisplay];
[CATransaction commit];
}

#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR

- (void)addSubview:(nonnull LOTView *)view
Expand Down Expand Up @@ -302,7 +314,8 @@ - (void)setAnimationProgress:(CGFloat)animationProgress {
_animationProgress = animationProgress;
[CATransaction begin];
[CATransaction setDisableActions:YES];
[_compContainer displayWithFrame:@(frame) forceUpdate:YES];
_compContainer.currentFrame = @(frame);
[_compContainer setNeedsDisplay];
[CATransaction commit];
}

Expand Down Expand Up @@ -431,7 +444,7 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)complete {
}
if (!_isAnimationPlaying || !complete || ![anim isKindOfClass:[CABasicAnimation class]]) return;
NSNumber *frame = [(CABasicAnimation *)anim toValue];
_animationProgress = frame.floatValue / _sceneModel.endFrame.floatValue;
_animationProgress = frame.floatValue / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue);
_isAnimationPlaying = NO;
_playAnimation.delegate = nil;
[_compContainer removeAllAnimations];
Expand Down
2 changes: 2 additions & 0 deletions lottie-ios/Classes/PublicHeaders/LOTAnimationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ typedef void (^LOTAnimationCompletionBlock)(BOOL animationFinished);
/// Stops the animation and rewinds to the beginning. The completion block will be called.
- (void)stop;

/// Sets progress of animation to a specific frame. If the animation is playing it will stop and the compeltion block will be called.
- (void)setProgressWithFrame:(nonnull NSNumber *)currentFrame;

/**
* Sets the keyframe value for a specific After Effects property at a given time.
Expand Down

0 comments on commit ad9303e

Please sign in to comment.