SkillAgentSearch skills...

LSAnimator

⛓ Easy to Read and Write Multi-chain Animations Lib in Objective-C and Swift.

Install / Use

/learn @Lision/LSAnimator

README

language  language  CocoaPods  Carthage compatible  Build Status  License MIT  CocoaPods  Support

中文介绍

This project is inspired by JHChainableAnimations!

Why Choose LSAnimator & CoreAnimator?

You can write complex and easy-to-maintain animations in just a few lines of code by use LSAnimator(Objective-C) or CoreAnimator(Swift).

Objective-C  Swift

What's The Multi-chain Animations?

CAAnimations and UIView animations are extremely powerful, but it is very hard to read when the animation is complicated.

Say I want to move myView 100 pixels to the right with spring and then incre 30 pixels to the width with inward easing when the movement has finished:

The Old Way

[UIView animateWithDuration:2.0
                          delay:0.0
         usingSpringWithDamping:0.8
          initialSpringVelocity:1.0
                        options:0
                     animations:^{
                         CGPoint newPosition = self.myView.frame.origin;
                         newPosition.x += 100;
                         self.myView.frame = CGRectMake(newPosition.x, newPosition.y, self.myView.frame.size.width, self.myView.frame.size.height);
                     } completion:^(BOOL finished) {
                         [UIView animateWithDuration:2.0
                                               delay:0.0
                                             options:UIViewAnimationOptionCurveEaseIn
                                          animations:^{
                                              CGSize newSize = self.myView.frame.size;
                                              newSize.width += 30;
                                              self.myView.frame = CGRectMake(self.myView.frame.origin.x, self.myView.frame.origin.y, newSize.width, newSize.height);
                                          } completion:nil];
                     }];

Thats pretty gross huh... With LSAnimator it is one line of code.

Using LSAnimator

LSAnimator *animator = [LSAnimator animatorWithView:self.myView];
animator.moveX(100).spring.thenAfter(2).increWidth(30).easeIn.animate(2);

Emmmmm...There is an animation library called JHChainableAnimations can also do this.

Whats wrong with JHChainableAnimations?

JHChainableAnimations has powerful chainable animations AND easy to read/write syntax, but it does not support for Multi-chain Animations.

Following the example above, assume now that the whole animation chain above needs to change the transparency of myView to zero at the same time:

Using LSAnimator

LSAnimator

With LSAnimator it is just need to add one line of code.

LSAnimator *animator = [LSAnimator animatorWithView:self.myView];
animator.moveX(100).spring.thenAfter(2).increWidth(30).easeIn.animate(2);
animator.concurrent.makeOpacity(0).animate(4);

Using JHChainableAnimations

JHChainableAnimations

Emmmmm...With JHChainableAnimations it is can not finished task. Trying to add the following code will cause the animation bug or crash.

JHChainableAnimator *animator = [[JHChainableAnimator alloc] initWithView:self.myView];
animator.moveX(100).spring.thenAfter(2).moveWidth(30).easeIn.animate(2);
animator.makeOpacity(0).animate(4);

LSAnimator VS JHChainableAnimations

  • Multi-chain Animations: Can complete all animation design needs, More flexible than JHChainableAnimations.
  • CALayer Support: Support CALayer initialization, JHChainableAnimations only supports UIView.
  • Parameter Auto-completion: Support parameter auto-completion, JHChainableAnimations does not support.

LSAnimator support parameter auto-completion, including the number of parameters and parameter types:

LSAnimator

JHChainableAnimations is not friendly when actually writing code.

JHChainableAnimations

JHChainableAnimations is still a really good animation library and LSAnimator is standing on the shoulders of it.

Features

  • Swift Support: Swift 3.2 ~ 4 Support.
  • Friendly Swift Interface: Added friendly Swift interface in separate framework.
  • Multi-chain Animations: Can complete all animation design needs.
  • CALayer Support: Support CALayer initialization.
  • Parameter Auto-completion: Support parameter auto-completion.
  • Support for Animation Hooks: Added pre-animation and post-animation hooks for each animation step. Added a final completion hook that fires when all animation chains have completed.
  • Non-intrusive: There is no need to make the view/layer class inherit from other base class.

Usage

Creating an Animator

// UIView initialization
LSAnimator *viewAnimator = [LSAnimator animatorWithView:self.myView];
LSAnimator *viewAnimator = [[LSAnimator alloc] initWithView:self.myView];

// CALayer initialization
LSAnimator *layerAnimator = [LSAnimator animatorWithLayer:self.myLayer];
LSAnimator *layerAnimator = [[LSAnimator alloc] initWithLayer:self.myLayer];

Animating

Chainable properties like moveX(x) must come between the animator and the animate(t) function.

Below is an example of how to double an objects size over the course of one second.

animator.makeScale(2.0).animate(1.0);

Combining Animations

If you want to move the view while you scale it, add another chainable property. Order is not important.

animator.makeScale(2.0).moveXY(100, 50).animate(1.0);
// the same as animator.moveXY(100, 50).makeScale(2.0).animate(1.0);

Note: Combining Animations works only for the animation that needs to be done in the same step.

If the animations have different durations. When they can not be done in the same animation step, they need to use Multi-chain Animations.

A full list of chainable properties can be found here.

Chaining Animations

To chain animations seperate the chains with the thenAfter(t) function.

Below is an example of how to scale and object for 0.5 seconds, and then move it for 1 second when that is done.

animator.makeScale(2.0).thenAfter(0.5).moveXY(100, 50).animate(1.0);

Animation Effects

Animation Effects To add an animation effect, call the effect method after the chainable property you want it to apply to.

Below is an example of scaling a view with a spring effect.

animator.makeScale(2.0).spring.animate(1.0);

If you add 2 to the same chainable property the second will cancel the first out.

animator.makeScale(2.0).bounce.spring.animate(1.0);
// The same as animator.makeScale(2.0).spring.animate(1.0);

A full list of animation effect properties can be found here.

Anchoring

To anchor your view call an achoring method at some point in an animation chain. Like effects, calling one after another in the same chain will cancel the first out.

Below is an example of rotating a view around different anchor points.

animator.rotateZ(180).anchorTopLeft.thenAfter(1.0).rotateZ(90).anchorCenter.animate(1.0);
// animator.rotateZ(90).anchorTopLeft.anchorCenter == animator.rotateZ(90).anchorCenter

A full list of anchor properties can be found here.

Delays

To delay an animation call the wait(t) or delay(t) chainable property.

Below is an example of moving a view after a delay of 0.5 seconds.

animator.moveXY(100, 50).wait(0.5).animate(1.0);
// The same as animator.moveXY(100, 50).delay(0.5).animate(1.0);

Completion

To run code after an animation finishes call the animateWithCompletion(t, completion)* function.

animator.makeX(0).animateWithCompletion(1.0, ^{
	NSLog(@"Animation Done");
});

Repeating Animations

You can repeat an animation by replacing the thenAfter(time) method with the repeat(time, count) method. This will repeat the previously defined animations.

animator.increWidth(30).spring.repeat(0.5, 3).moveXY(100, 50).animate(1.0);

You can repeat the last part of an animation by calling animateWithRepeat(time, count).

animator.increWidth(30).spring.animateWithRepeat(0.5, 3);

Callbacks

You can hook into the different steps of the animation process by calling the `preAnimationBl

Related Skills

View on GitHub
GitHub Stars1.7k
CategoryDevelopment
Updated1mo ago
Forks159

Languages

Objective-C

Security Score

100/100

Audited on Feb 22, 2026

No findings