Git Product home page Git Product logo

mtanimation's Introduction

MTAnimation

Animate UIView/NSView with 25+ timing functions. (Bounce, elastic, exponential, etc.)

Allows you to animate views in your app in the way you're familiar with (e.g. [UIView animateWithDuration:animations:]) but adds 25+ easing functions (from jQuery) to make your animations more visceral.

Advantages:

  • Methods very similar to Apple's API.
  • No Swizzling.
  • No need to mess with keypaths, just change the properties on UIView and you're golden.
  • Proper transform matrix interpolation, so rotations look correct.
  • Install with cocoapods.
  • Category methods prefixed.

Installation

In your Podfile, add this line:

pod "MTAnimation"

Then add the import:

// Same import for both iOS/OSX
#import <UIView+MTAnimation.h>

Preview

Animation Sample

Example App

iOS

  • Clone the repo (or download the zip) and run the iPad demo app to play around.

OSX

  • Download and run a developer signed Mac Example

  • Clone the repo (or download the zip) and build & run the mac app yourself.

Example Usage

Similar to the UIKits animation methods but you must supply an array of all the views you will be animating and an easing function.

[UIView mt_animateWithViews:@[view]
                   duration:0.25
             timingFunction:kMTEaseOutBack
                 animations:^{
                     CGRect r             = _logoImageView.frame;
                     r.origin.x           = 50;
                     _logoImageView.frame = r;
                 }];

You can animate:

UIView/NSView - frame
UIView/NSView - bounds
UIView        - center
UIView/NSView - alpha
UIView        - transform (CGAffineTransform)
CALayer       - transform (CATransform3D)

You can cut an animation into parts (using the range param). You might use this to swap the view half way through a flip animation:

_logoImageView.image = [UIImage imageNamed:@"logo"];
[UIView mt_animateWithViews:[view mt_allSubviews]
                   duration:0.25
                      delay:0
             timingFunction:kMTEaseOutBack
                      range:MTMakeAnimationRange(0, 0.135)
                    options:0
                 animations:^{
                     CGFloat radians                 = mt_degreesToRadians(_endRotation);
                     _logoImageView.layer.transform  = CATransform3DMakeRotation(radians, 0, 1, 0);
                 } completion:^{
                     _logoImageView.image = [UIImage imageNamed:@"logo-flip"];
                     [UIView mt_animateWithWithViews:[view mt_allSubviews]
                                            duration:0.25
                                               delay:0
                                      timingFunction:kMTEaseOutBack
                                               range:MTMakeAnimationRange(0.135, 1)
                                             options:0
                                          animations:^{
                                              CGFloat radians                 = mt_degreesToRadians(_endRotation);
                                              _logoImageView.layer.transform  = CATransform3DMakeRotation(radians, 0, 1, 0);
                                          } completion:^{
                                          }];
                 }];

This code will animate until the image is sideways, then swap out the image view's image and continue the animation so it looks like it has a backside.

Notes

  • The view you animate must be layer backed. See [NSView setWantsLayer:].

Author

Adam Kirk (@atomkirk)

Contributing

I have TODO: comments on stuff I need some help with, so feel free.

Credits

Inspired by Nocho Soto's NSBKeyframeAnimation Library

Code extracts from Ivan Vu�ica & Amr Aboelela work on CAAnimation

Easing functions from jQuery

License

Copyright (c) 2010 Mysterious Trousers, LLC (http://www.mysterioustrousers.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

mtanimation's People

Contributors

atomkirk avatar hoiogi avatar liggitt avatar mikeger avatar seivan avatar ushio avatar

Watchers

 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.