GithubHelp home page GithubHelp logo

mikel063093 / anim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from onurersel/anim

0.0 2.0 0.0 5.62 MB

Swift animation library for iOS, tvOS and macOS.

License: MIT License

Ruby 4.51% Objective-C 1.01% Shell 0.37% Swift 94.11%

anim's Introduction

anim: Swift animation library for iOS, tvOS and macOS.


CocoaPods Carthage compatible Build Status codecov.io codebeat badge

anim is an animation library written in Swift with a simple, declarative API in mind.

// moves box to 100,100 with default settings
anim {
    self.box.frame.origin = CGPoint(x:100, y:100)
}
// after that, waits 100 ms
.wait(0.1)
// moves box to 0,0 after waiting
.then {
    self.box.frame.origin = CGPoint(x:0, y:0)
}
// displays message after all animations are done
.callback {
    print("Just finished moving ๐Ÿ“ฆ around.")
}

It supports a bunch of easing functions and chaining multiple animations. It's a wrapper on Apple's UIViewPropertyAnimator on its core, and falls back to UIView.animate on versions before iOS and tvOS 10. It uses NSAnimationContext on macOS.

Examples

Example projects are available at examples/ folder and as targets on XCode project.

Bonfire

Profile

Menu

Message


Installation

Cocoapods

pod 'anim'

Carthage

github "onurersel/anim"

Manually

Or simply drag the swift files inside src/ folder into your project.


API

For complete documentation, visit http://onurersel.github.io/anim/.

Initialize animations with anim constructor.

// Initialize with default settings
anim {
    // animation block
}
// or initialize with it's own settings
anim { (settings) -> (animClosure) in
    settings.delay = 1
    settings.duration = 0.7
    settings.ease = .easeInOutBack

    return {
        // animation block
    }
}
// or initialize layout constraint animations just by passing the parent view
anim(constraintParent: self.view) {
    // animation block
}

anim(constraintParent: self.view) { (settings) -> (animClosure) in
    // settings...
    return {
        // animation block
    }
}

// you don't need to call layoutIfNeeded() before or inside the
// animation blocks, it's handled by anim
//
// for example to update constant value of a constraint,
// you can just change it inside the animation block
let width: NSLayoutConstraint //...
anim(constraintParent: self.view) {
    width.constant = 100 // new value
}
// that's it!

Chain animations with then function.

anim {}
.then{
    // next animation block
}
anim {}
.then { (settings) -> animClosure in
    settings.duration = 1
    return {
        // next animation block
    }
}
anim {}
.then(constraintParent: self.view) {
    // chaining constraint animations
}
.then(constraintParent: self.view) { (settings) -> animClosure in
    settings.duration = 1
    return {
        // next animation block for constraints
    }
}

Wait between animation steps with wait function.

anim{}.wait(0.25).then{} //...

Insert callbacks between animation steps with .callback function.

anim{}
.callback {
    // custom block
}
.then{} //...

Stop animations with stop function.

let animation = anim{}.then{} // ...
animation.stop()

Default settings

You can change default animation settings through anim.defaultSettings property.

anim.defaultSettings.ease = .easeInOutCubic

Easing

anim.Ease exposes a bunch of easing options.


Roadmap

  • Chaining animations
  • Wait, callback functions
  • Constraint animations
  • iOS 8 and 9 support
  • macOS support
  • tvOS support
  • Example projects
  • API for choreographing animations
  • Grouping animations
  • Easing with spring
  • Shape animations

License

anim is released under the MIT license. See LICENSE for details.

anim's People

Contributors

onurersel avatar ivanbarisic05 avatar lfarah avatar readmecritic avatar tengfoung avatar

Watchers

James Cloos avatar Miguel Alegria 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.