Giter Club home page Giter Club logo

yapanimator's Introduction

YapAnimatorLogo

YapAnimator is your fast and friendly physics-based animation system. YapAnimator was built with ease-of-use in mind, keeping you sane and your designer very, very happy. All animations are interruptable, include completion blocks, and allow you to apply forces to them (e.g. adding the velocity from a gesture in a transition). We've included Animatable protocol conformance for some commonly animated types (CG types), but it's really easy to add conformance to any other type. You can animate anything that you can represent and compose with an array of Doubles — view properties, music volume, morphing between bezier paths, colors, smoothing brush strokes, the list goes on… use your imagination!

Build Status CocoaPods Compatible Platform

Why use YapAnimator?

Because it's insanely easy to use and makes beautiful animations, that's why. There are other physics-based animation systems out there (e.g. UIKit's spring animations, Facebook's Pop), but they still require writing too much code, bookkeeping, and hand-holding for our taste. YapAnimator represents a distilled n-th iteration of code that we've been using in our own apps for years. We find it invaluable in our day-to-day and think that you will too.

Built-in Extensions

YapAnimator comes with a handy extension bolted on to CALayer and UIView/NSView, providing one-liner animations under the animatedLayer and animated properties, respectively.

CircleAnimationExample

func handle(gesture: UIPanGestureRecognizer) {

	if gesture.state == .began {
		squircle.animated.cornerRadius.animate(to: squircle.bounds.width / 2.0)
		squircle.animated.rotationZ.animate(to: .pi)
	else if gesture.state == .changed {
		squircle.animated.position.instant(to: gesture.location(in: nil))
	} else if gesture.state == .ended {
		squircle.animated.position.animate(to: self.view.center)
		squircle.animated.cornerRadius.animate(to: 0)
		squircle.animated.rotationZ.animate(to: 0)
	}
}

Custom Animators

Creating a custom animator is straightforward:

  • initialValue This sets the initial value of the animator and informs it what type it will be animating.
  • willBegin Called just before motion starts. Return the actual value of the property that you'll be animating. This allows the animator to sync up with that value in case it was changed outside of the scope of the animator. (optional)
  • eachFrame Called each frame of the animation — this is typically where you'd apply the animator's current.value to the property that you're animating. You can also use it to check values to trigger other actions / animations.
frameAnimator = YapAnimator(initialValue: square.frame, willBegin: { [unowned self] in
	return self.square.frame
}, eachFrame: { [unowned self] (animator) in
	self.square.frame = animator.current.value
})

SquareFrameExample

frameAnimator.bounciness = 1.5

frameAnimator.animate(to: square.frame.insetBy(dx: -50, dy: -50), completion: { animator, wasInterrupted in
	if !wasInterrupted {
		// animate back to the original value
		animator.animate(to: animator.current.value.insetBy(dx: 50, dy: 50))
	}
})

Questions?

Feel free to ask your question in an issue. We will respond there, and amend this read me/start a wiki if the answer seems like it would benefit others.

Credits

YapAnimator is owned and maintained by Yap Studios.

yapanimator's People

Contributors

3lvis avatar emoryalimam avatar olliewagner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yapanimator's Issues

Swift 5

Hi!

This is an awesome library!! Is it going to be updated to Swift 5?

Thanks for all your effort!! ^_^

Examples

hello dears,
I hope this awesome library by supported by documentation and more examples...
thanks in advance... 👍

Support MacOS

Dear Author,
I found your code did not support MacOS as you described, UIKit / UITextField is for iOS, not for MacOS, have you tried MacOS? May i have your update for supporting MacOS?

NSColor.ColorType build error on macOS with Swift 4

Base SDK 10.13 ~~ no other available
Target 10.12 ~~ changing target to anything else (including 10.13) does not seem to make a difference.

On YapAnimator | Animatable.swift at build-time
line 236: guard let ci = CIColor(color: self) else { return Array<Double>(repeating: 0, count: type(of:self).count) } type seems to be at fault. Cannot call value of non-function type 'NSColor.ColorType'

Any ideas?

Control duration of animation?

Is it possible to change the duration length of the animation? From a quick glance it seems like YapAnimator calculates a nice duration based on the bounciness and speed, right?

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.