Coder Social home page Coder Social logo

animationplanner's Introduction

Animation Planner logo

AnimationPlanner

โ›“ Chain multiple UIView animations without endless closure nesting. Create your animation sequence all on the same indentation level using a clear, concise syntax.

๐Ÿคน Used for all exuberant animations in OK Video ๐Ÿ“ฒ

๐Ÿ“– Check out the documentation to get up to speed, or read on to see a little example.

How do I plan my animations?

๐Ÿ“ฆ Add AnimationPlanner to your project (using Swift Package manager) and start typing AnimationPlanner.plan to embark on your animation journey. Like whatโ€˜s happening in the code below.

AnimationPlanner.plan {
    Animate(duration: 0.32, timingFunction: .quintOut) {
        view.alpha = 1
        view.center.y = self.view.bounds.midY
    }
    Wait(0.2)
    Animate(duration: 0.32) {
        view.transform = CGAffineTransform(scaleX: 2, y: 2)
        view.layer.cornerRadius = 40
        view.backgroundColor = .systemRed
    }.timingFunction(.quintOut)
    Wait(0.2)
    AnimateSpring(duration: 0.25, dampingRatio: 0.52) {
        view.backgroundColor = .systemBlue
        view.layer.cornerRadius = 0
        view.transform = .identity
    }
    Wait(0.58)
    Animate(duration: 0.2) {
        view.alpha = 0
        view.transform = .identity
        view.frame.origin.y = self.view.bounds.maxY
    }.timingFunction(.circIn)
}.onComplete { finished in
    view.removeFromSuperview()
}

The above code results in the following animation sequence. For more examples see the Sample App available when cloning the repo.

Note: The example uses custom extension methods on CAMediaTimingFunction, included with the framework

Installation

๐Ÿ›  Adding AnimationPlanner as a package dependency

  1. Go to File -> Add Packages
  2. Paste https://github.com/PimCoumans/AnimationPlanner in the search bar and click on "Add Package"
  3. Select the target(s) in which you want to use AnimationPlanner

๐Ÿ“ฆ Swift Package Manager

Manually add AnimationPlanner as a package dependency in package.swift, by updating your package definition with:

  dependencies: [
    .package(name: "AnimationPlanner", url: "https://github.com/PimCoumans/AnimationPlanner.git", .branch("main"))
  ],

And updating your targetโ€˜s dependencies property with dependencies: ["AnimationPlanner"]

๐Ÿ”ฎ Future plans

While this API removes a lot of unwanted nesting in completion closures when using traditional UIView.animate... calls, a project is never finished and for future versions I have the following plans:

  • Remove usage of inaccurate DispatchQueue.main.asyncAfter, currently used to add delays for non-UIView animations or bridging gaps between steps.
  • Maybe even allow this package to play more nicely with SwiftUI? No idea what that would look like though, any ideas?

Got any feedback or suggestions? Please let me know! โœŒ๐Ÿป

โ†’ twitter.com/pimcoumans

animationplanner's People

Contributors

pimcoumans avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.