Skip to content
 
 

Repository files navigation

DaisyChain

Updated Fork of alikaragoz - DaisyChain

DaisyChain is a micro framework which makes UIView animations chaining dead simple. It uses the exact same interface you are familiar with.

Chaining made simple

We all have seen or written code which looks like this:

UIView.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 0.0)
}, completion: { _ in
    UIView.animate(withDuration: 0.5, animations: {
        view.center = CGPoint(x: 100.0, y: 0.0)
    }, completion: { _ in
        UIView.animate(withDuration: 0.5, animations: {
            view.center = CGPoint(x: 100.0, y: 100.0)
        }, completion: { _ in
            UIView.animate(withDuration: 0.5, animations: {
                view.center = CGPoint(x: 0.0, y: 100.0)
            }, completion: { _ in
                UIView.animate(0.5, animations: {
                    view.center = CGPoint(x: 0.0, y: 0.0)
                })
            })
        })
    })
})

This can go pretty far, it is also known as callback hell. It's not very flexible and hard to read.

With DaisyChain we can rewrite that same code like this:

let chain = DaisyChain()

chain.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 0.0)
})

chain.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 100.0, y: 0.0)
})

chain.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 100.0, y: 100.0)
})

chain.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 100.0)
})

chain.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 0.0)
})

As you can the the code has been flattened, this allows you to easily modify the order of the steps or the addition of new steps.

Or if you would prefer your code to be more succinct:

let chain = DaisyChain()

chain.animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 0.0)
}).animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 100.0, y: 0.0)
}).animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 100.0, y: 100.0)
}).animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 100.0)
}).animate(withDuration: 0.5, animations: {
    view.center = CGPoint(x: 0.0, y: 0.0)
})

Breakable chains

DaisyChain also adds a simple way to break animation sequences, simply set the broken property to true to break a chain:

chain.broken = true

To continue chaining animations, you'll need to change it back to false or create a new chain.

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'DaisyChain', :git => 'https://github.com/Nordeast/DaisyChain.git'

License

DaisyChain is available under the MIT license.

About

🔗 Easy animation chaining

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages