Convert Figma logo to code with AI

draveness logoDKChainableAnimationKit

A DSL to make animation easy on iOS with Swift.

1,894
110
1,894
13

Top Related Projects

14,077

A library to simplify iOS animations in Swift.

Block-based animations made easy, comes with easing functions and a CASpringAnimation replacement.

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.

5,539

A collection of animation examples for iOS apps.

19,660

An extensible iOS and OS X animation library, useful for physics-based interactions.

Quick Overview

DKChainableAnimationKit is a Swift library that provides a chainable interface for creating UIView animations. It simplifies the process of creating complex animations by allowing developers to chain multiple animation methods together, resulting in more readable and maintainable code.

Pros

  • Easy-to-use chainable syntax for creating animations
  • Supports a wide range of animation properties (e.g., position, size, rotation, opacity)
  • Allows for easy creation of complex, multi-step animations
  • Compatible with both Swift and Objective-C projects

Cons

  • Limited to UIView animations, not suitable for more advanced animation needs
  • May have a slight learning curve for developers unfamiliar with chainable APIs
  • Potential performance overhead compared to native UIView animations for very simple cases
  • Not actively maintained (last update was in 2017)

Code Examples

Creating a simple fade and move animation:

view.animation
    .fadeOut()
    .moveX(100)
    .animate(1.0)

Chaining multiple animations with different durations:

view.animation
    .makeScale(2.0)
    .animate(0.5)
    .makeScale(1.0)
    .animate(0.3)
    .makeBackground(.red)
    .animate(0.2)

Creating a spring animation:

view.animation
    .moveY(100)
    .spring
    .animate(0.5)

Getting Started

  1. Add DKChainableAnimationKit to your project using CocoaPods:
pod 'DKChainableAnimationKit'
  1. Import the library in your Swift file:
import DKChainableAnimationKit
  1. Start using the chainable animations on your UIViews:
let myView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
myView.animation
    .makeX(200)
    .makeY(300)
    .makeScale(1.5)
    .makeBackground(.blue)
    .animate(0.5)

This will create a view, move it to (200, 300), scale it by 1.5, change its background color to blue, and animate all these changes over 0.5 seconds.

Competitor Comparisons

14,077

A library to simplify iOS animations in Swift.

Pros of Spring

  • More comprehensive animation library with a wider range of pre-built animations
  • Includes a loading animation feature
  • Supports both Swift and Objective-C

Cons of Spring

  • Larger codebase, potentially leading to increased app size
  • May have a steeper learning curve for beginners

Code Comparison

Spring:

view.animate(.pop(repeatCount: 1)) {
    view.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
}

DKChainableAnimationKit:

view.animation.makeScale(1.5).spring.animate(0.5)

Key Differences

  • Spring offers a more extensive set of pre-built animations, while DKChainableAnimationKit focuses on chainable custom animations
  • Spring includes additional features like loading animations, whereas DKChainableAnimationKit is more lightweight and focused on core animation capabilities
  • DKChainableAnimationKit's syntax is more concise and chainable, while Spring's API is more descriptive and explicit

Use Cases

  • Choose Spring for projects requiring a wide range of pre-built animations and loading indicators
  • Opt for DKChainableAnimationKit when you need a lightweight solution with chainable custom animations and prefer a more concise syntax

Block-based animations made easy, comes with easing functions and a CASpringAnimation replacement.

Pros of RBBAnimation

  • More lightweight and focused on core animation functionality
  • Provides a simpler API for basic animations
  • Better suited for projects requiring low-level animation control

Cons of RBBAnimation

  • Less feature-rich compared to DKChainableAnimationKit
  • Lacks the extensive chainable animation options
  • May require more code for complex animation sequences

Code Comparison

RBBAnimation:

RBBSpringAnimation *animation = [RBBSpringAnimation animationWithKeyPath:@"position.y"];
animation.fromValue = @(view.center.y);
animation.toValue = @(view.center.y + 100);
animation.duration = 0.5;
[view.layer addAnimation:animation forKey:@"bounce"];

DKChainableAnimationKit:

view.dk_makeAnimation()
    .moveY(100)
    .spring
    .duration(0.5)
    .animate()

RBBAnimation offers a more traditional Objective-C approach to animations, while DKChainableAnimationKit provides a more modern, chainable Swift syntax. DKChainableAnimationKit allows for more concise and readable animation code, especially for complex sequences. However, RBBAnimation may be preferred for projects requiring fine-grained control over individual animation properties.

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.

Pros of MGSwipeTableCell

  • Specifically designed for creating swipeable table cells in iOS
  • Offers a wide range of customization options for swipe buttons and actions
  • Provides built-in support for common swipe gestures and animations

Cons of MGSwipeTableCell

  • Limited to table view cell animations, not general-purpose
  • Requires more setup and configuration for basic swipe functionality
  • Less flexible for creating complex, chained animations

Code Comparison

MGSwipeTableCell:

let cell = MGSwipeTableCell()
cell.rightButtons = [MGSwipeButton(title: "Delete", backgroundColor: .red)]
cell.leftSwipeSettings.transition = .rotate3D

DKChainableAnimationKit:

view.animation.moveX(100).moveY(100).rotateZ(360).animate(1.0)

MGSwipeTableCell focuses on creating swipeable table cells with customizable buttons and transitions, while DKChainableAnimationKit provides a more general-purpose, chainable animation system for UIView elements. MGSwipeTableCell is ideal for implementing swipe-to-action functionality in table views, whereas DKChainableAnimationKit offers greater flexibility for creating complex animations across various UI elements.

5,539

A collection of animation examples for iOS apps.

Pros of popping

  • More comprehensive animation library with a wider range of effects
  • Supports both Objective-C and Swift
  • Includes physics-based animations for more realistic effects

Cons of popping

  • Steeper learning curve due to more complex API
  • Less intuitive for simple animations
  • Requires more setup and configuration

Code Comparison

popping:

POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 400, 400)];
anim.springBounciness = 20.0f;
anim.springSpeed = 20.0f;
[layer pop_addAnimation:anim forKey:@"size"];

DKChainableAnimationKit:

view.animation.makeScale(2.0).spring.animate(1.0)

Summary

popping offers a more powerful and flexible animation framework with physics-based effects, supporting both Objective-C and Swift. However, it has a steeper learning curve and requires more setup. DKChainableAnimationKit provides a simpler, more intuitive API for basic animations, making it easier to use for simple tasks but potentially limiting for complex animations.

19,660

An extensible iOS and OS X animation library, useful for physics-based interactions.

Pros of pop

  • More powerful and flexible, supporting a wider range of animations and physics-based interactions
  • Better performance, especially for complex animations, due to its use of Core Animation
  • Extensive documentation and community support, being a Facebook-backed project

Cons of pop

  • Steeper learning curve, requiring more setup and configuration
  • Less intuitive API for simple animations compared to DKChainableAnimationKit
  • Heavier framework, which may impact app size and compilation time

Code Comparison

DKChainableAnimationKit:

view.animation.moveX(100).moveY(100).rotate(45).animate(1.0)

pop:

POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim.toValue = @(100);
anim.springBounciness = 4.0;
[view.layer pop_addAnimation:anim forKey:@"moveX"];

Summary

Pop offers more power and flexibility for complex animations, while DKChainableAnimationKit provides a simpler, more intuitive API for basic animations. Pop excels in performance and community support but has a steeper learning curve. DKChainableAnimationKit is easier to use for simple animations but may not be as suitable for complex or physics-based interactions.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead.

With DKChainableAnimationKit

Using DKChainableAnimationKit, you do not need to write the extra parentheses.

view.animation.makeScale(2.0).spring.animate(1.0)

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like DKNightVersion in your projects. See the Get Started section for more details.

Podfile

use_frameworks!

pod "DKChainableAnimationKit", "~> 2.0.0"

Installation with Carthage

Carthage is a depency manager for Objectiv-C and Swift.

Cartfile

github "Draveness/DKChainableAnimationKit"

Usage

Import DKChainableAnimationKit in proper place.

import DKChainableAnimationKit

DKChainableAnimationKit is designed to be extremely easy to use. First call animation method on UIView instance, and then add the animation you want followed by a animate(t) method.

view.animation.moveX(100.0).animate(1.0)

Animating

Chainable properties or functions like moveX(x) must come between the animate(duration) function.

view.animation.moveX(100.0).animate(1.0)

If you want mutiple animation at one time.

view.animation.moveX(100.0).moveY(100.0).animate(1.0)

This will move the view 100 point right and 100 point down at the same time. Order is not important.

Chaining Animations

To chain animations separate the chains with the thenAfter(duration) function.

view.animation.moveX(100.0).thenAfter(1.0).makeScale(2.0).animate(2.0)

This will move the view for one second and after moving, it will scale for two seconds.

Animation Effects

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

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

view.animation.moveX(10).spring.animate(1.0)

If you add two animation effect, the first will be cancel out.

view.animation.moveX(10).spring.bounce.animate(1.0)
// The same as view.animation.moveX(10).bounce.animate(1.0)

Anchoring

To anchor your view call an anchoring method at some point in an animation chain. And if you add two anchoring property, the first will be cancel like effects.

view.animation.rotate(180).anchorTopLeft.thenAfter(1.0).rotate(90).anchorCenter.animanimation

Delay

To delay an animation call the wait(time) or delay(time) chainable function.

view.animation.moveXY(100, 40).wait(0.5).animate(1.0)
view.animation.moveXY(100, 40).delay(0.5).animate(1.0)
delay

This will move the view after 0.5 second delay.

Completion

If you want to run code after an animation finishes, you are supposed to set the animationCompletion property or call animateWithCompletion(t, completion) function.

view.animation.makeX(0).animateWithCompletion(1.0, {
    println("Animation Done")
})

This is the same as

view.animation.animationCompletion = {
    println("Animation Done")
}
view.animation.makeX(0).animate(1.0)

And also the same as

view.animation.makeX(0).animate(1.0).animationCompletion = {
    println("Animation Done")
}

Bezier Paths

You can also animate a view along a UIBezierPath. Call bezierPathForAnimation method first and then add points or curves to it and us it in a chainable property.

let path = view.animation.bezierPathForAnimation()
path.addLintToPoint(CGPoint(x: 30, y: 40))
view.animation.moveOnPath(path).animate(1.0)

Animation effects does not work on path movement.


Chainable Properties

moveX(100.0)
moveY(100.0)
moveWidth(100.0)
moveHeight(100.0)
moveXY(100.0, 100.0)
makeX(100.0)
makeY(100.0)
makeOrigin(100.0, 100.0)
makeCenter(100.0, 100.0)
makeWidth(100.0)
makeHeight(100.0)
makeSize(100.0, 100.0)
makeFrame(rect) // let rect: CGRect
makeBounds(rect) // let rect: CGRect
makeScale(2.0)
makeScaleX(2.0)
makeScaleY(2.0)
makeOpacity(0.0)
makeBackground(purple) // let purple: UIColor
makeBorderColor(red) // let red: UIColor
makeBorderWidth(10.0)
makeCornerRadius(25.0)

To Do

  • Support OS X
  • Support Swift 2.0

Contact

  • If you have some advice open an issue or a PR.
  • Email [Draveness](mailto: i@draveness.me)

License

DKChainableAnimationKit is available under the MIT license. See the LICENSE file for more info.