• Stars
    star
    505
  • Rank 87,373 (Top 2 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

MTMigration

Manages blocks of code that only need to run once on version updates in iOS apps.
Objective-C
913
star
2

MTDates

A thread safe date calculation library with all the date functions you'll ever need.
Objective-C
343
star
3

MTGeometry

An extension to Core Graphics Geometry. Intersections, scaling, etc.
Objective-C
212
star
4

MTPDF

Objective-C PDF objects. Doing my part to help us stay out of the headache that is Core Foundation.
Objective-C
205
star
5

MTStringAttributes

Easier way to create an attributes dictionary for NSAttributedString
Objective-C
154
star
6

MTControl

Attach block handlers to UIControl objects jQuery style
Objective-C
114
star
7

MTQueue

Add blocks to queues in a super terse and readable way!
Objective-C
61
star
8

MYSCategoryProperties

Quickly add properties to categories using runtime associations.
Objective-C
60
star
9

MTPencil

Draw animated lines (like an invisible pencil) with Core Graphics. (Prototype, will get much better).
Objective-C
47
star
10

MTFittedScrollView

A UIScrollView subclass that resizes itself to fit around its content.
Objective-C
39
star
11

MYSForms

Easy forms for iOS
Objective-C
33
star
12

MYSRuntime

Obj-C Library that makes runtime self-inspection and class modification dead easy.
Objective-C
33
star
13

MTColorDistance

A category on UIColor. Pass in an array of colors and it will return the closest color to the receiver.
Objective-C
24
star
14

MTPocket

Cocoa Web Requests
Objective-C
23
star
15

EKEventToiCal

Returns a string in iCal format for an EKEvent object
Objective-C
22
star
16

MTBlockAlertView

An iOS Alert View that uses block-based delegation instead of protocols.
Objective-C
22
star
17

FatSecretKit

iOS client library for the FatSecret API
Objective-C
21
star
18

MYSSharedSettings

Access local settings and settings shared via iCloud with properties.
Objective-C
20
star
19

MTDateComponentsPicker

A picker for choosing date components. Allows some components to be undefined.
Objective-C
15
star
20

FakeContacts

An XCode project you can build onto the simulator or device to generate any number or random contacts for app testing
Objective-C
13
star
21

MYSCoreText

An Objective-C wrapper around Apple's Core Text framework.
Objective-C
11
star
22

MYSDynamicAlertView

An alert view that uses UIKit Dynamics to present a fun/interactive way to respond to alerts.
Objective-C
9
star
23

flunk

A gem for testing Ruby on Rails web APIs by simulating a client.
Ruby
6
star
24

MYSShared

A submodule that includes objc code that will more than likely be used in any objc project we do.
Objective-C
3
star
25

MTTimer

An Objective-C timer that restricts firing to a time range. If it's called BEFORE min, it waits for min. If it's called AFTER max, it's called at max.
Objective-C
3
star
26

MYSGravityActionSheet

An action sheet that uses UIKit Dynamics to present buttons in a playful, interesting way.
Objective-C
2
star
27

MYSTableView

Objective-C
1
star
28

Pocket

A curl gem that doesn't suck
Ruby
1
star