Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

A μ-framework which makes chaining UIView animations more simple and elegant [Swift 4, iOS 8+]

License

Notifications You must be signed in to change notification settings

DomainGroupOSS/swift-chainable-animations

Repository files navigation

swift-chainable-animations

Status

This framework is no longer being maintained.

Description

A μ-framework which makes chaining UIView animations more simple and elegant.

Background

When using the UIView.animate api, you may find yourself using the completion to set up a new animation. This can quickly lead to code which is hard to read and suffers from the dreaded Pyramid Of Doom.

Pyramid Of Doom

How to get it

Note

It is not recommended to use this framework as it has been archived.

Manually

Download https://github.com/DomainGroupOSS/swift-chainable-animations/blob/master/ChainableAnimations/UIViewAnimationExtensions.swift and add it to your project. Job done!

Carthage

git "DomainGroupOSS/swift-chainable-animations" "0.1.1"    

Cocoapods

pod "SwiftChainableAnimations", "0.1.1" 

Usage

ChainableAnimations is a single-file μ-framework which provides an alternate UIView api:

  • Use .prepareAnimation(...) to define the first animation...
  • ... and .then(...) any number of time afterwards to define a chain of linked animations, executed one after another.
  • Animations will not be performed until you call .animate(...).
  • Parameters for all functions follow the existing UIView.animate conventions and will do what you expect them to.

Before

UIView.animate(withDuration: 0.15, delay: 0.0, options: .curveEaseIn, animations: {
    self.titleImageView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}, completion: { _ in
    UIView.animate(withDuration: 0.4, delay: 0.0, options: .curveEaseOut, animations: {
        self.titleImageView.transform = CGAffineTransform.identity
    }, completion: nil)
})

After

import ChainableAnimations

UIView.prepareAnimation(withDuration: 0.15, options: .curveEaseIn) {
    self.titleImageView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}.then(withDuration: 0.4, options: .curveEaseOut) {
    self.titleImageView.transform = CGAffineTransform.identity
}.animate()

Before

UIView.animate(withDuration: stageDuration, delay: 0, options: .curveEaseIn, animations: stageOne) { _ in
    UIView.animate(withDuration: stageDuration, delay: 0, options: .curveEaseIn, animations: stageTwo, completion: { _ in
        UIView.animate(withDuration: stageDuration, delay: 0, options: .curveEaseIn, animations: stageThree, completion: nil)
    })
}

After

import ChainableAnimations

UIView
    .prepareAnimation(withDuration: stageDuration, delay: 0, options: .curveEaseIn, animations: stageOne)
    .then(withDuration: stageDuration, delay: 0, options: .curveEaseIn, animations: stageTwo)
    .then(withDuration: stageDuration, delay: 0, options: .curveEaseIn, animations: stageThree)
    .animate()

About

A μ-framework which makes chaining UIView animations more simple and elegant [Swift 4, iOS 8+]

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •