• Stars
    star
    951
  • Rank 48,061 (Top 1.0 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

Concise syntax for the Pop animation framework.

POP+MCAnimate License MIT

Badge w/ Version Badge w/ Platform

Concise syntax for the Pop animation framework. For more on the motivation behind this experiment, read this blog post.

Installation

Add the following to your CocoaPods Podfile

pod 'POP+MCAnimate', '~> 2.0'

or clone as a git submodule,

or just copy files in the POP+MCAnimate folder into your project.

Using POP+MCAnimate

Breaking change: Methods and properties have been prefixed with pop_. See section on shorthand syntax below.

Replace this:

POPSpringAnimation *animation = [self.boxView pop_animationForKey:@"bounds"];
if (!animation) {
    animation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewBounds];
}

animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
[self.boxView pop_addAnimation:animation forKey:@"bounds"];

With this:*

self.boxView.spring.bounds = CGRectMake(0, 0, 200, 200);

Spring Animation

You can configure velocity, springBounciness and springSpeed.

self.boxView.velocity.center = [pan velocityInView:self.boxView];
self.boxView.springBounciness = 20;
self.boxView.springSpeed = 20;
self.boxView.spring.center = viewCenter;

Decay Animation

You can configure velocity and decayDeceleration.

self.boxView.velocity.center = [pan velocityInView:self.boxView];
self.boxView.decayDeceleration = 0.998;
[self.boxView.decay center];

Basic Animation

You can configure duration and use different timing functions by swapping out easeInEaseOut for easeIn, easeOut or linear.

self.boxView.duration = 1;
self.boxView.easeInEaseOut.center = viewCenter;

Grouping and Completion Handlers

Block-based methods are provided on NSObject similar to UIKit block-based animation methods. The completion block waits for all animations in the animate block to complete before executing.

[NSObject animate:^{
  self.boxView.spring.alpha = 0.5;
  self.boxView.spring.bounds = CGRectMake(0, 0, 200, 200);
  self.boxView.spring.backgroundColor = [UIColor blueColor];
} completion:^(BOOL finished) {
  self.boxView.alpha = 1;
  self.boxView.spring.bounds = CGRectMake(0, 0, 100, 100);
  self.boxView.spring.backgroundColor = [UIColor redColor];
  self.boxView.spring.center = viewCenter;
}];

If you need to stop animations mid-way, use the stop proxy:

[self.boxView.stop bounds];

The finished flag in the completion handler will return NO if any of the animations in the group were stopped before completion.

Staggering Animations

Big thanks to @borndangerous and @bradjasper for their suggestion on beginTime. Great idea from @borndangerous on using sequences.

Set the beginTime property before any animations to stagger the animations by the said amount:

circle.beginTime = CACurrentMediaTime() + 0.1
circle.spring.alpha = 1;
circle.spring.scaleXY = CGPointMake(1, 1);

Once beginTime is set, it will persist until removed (by setting to 0), so all animations following that will be affected (which is probably what you want.)

If you work with NSArrays, it's even easier using the -sequenceWithInterval:animations:completion: method:

[circles sequenceWithInterval:0.1 animations:^(UIView *circle, NSInteger index){
    circle.spring.center = position;
    circle.spring.alpha = 1;
    circle.spring.scaleXY = CGPointMake(1, 1);
} completion:^(BOOL finished){
}];

Custom Properties

You can make any property animatable by first declaring it:

[UILabel registerAnimatablePropertyWithName:@"textColor" readBlock:^(UILabel *label, CGFloat values[]) {
    POPUIColorGetRGBAComponents(label.textColor, values);
} writeBlock:^(UILabel *label, const CGFloat values[]) {
    label.textColor = POPUIColorRGBACreate(values);
} threshold:0.01];

You do this by providing a read block, write block and threshold to tell Pop how to get and set numerical values on your property and the smallest increment to change it by. Later, just animate as usual:

self.messageLabel.spring.textColor = [UIColor blackColor];

Shorthand*

The above examples require the use of shorthand so you can drop the pop_ prefix from methods and properties. Just include the following in your pre-compiled header file after importing UIKit:

#define MCANIMATE_SHORTHAND
#import <POP+MCAnimate.h>

Remarks

The list of supported properties are:

  • CALayer (and subclasses)

    • backgroundColor
    • bounds
    • opacity
    • position
    • zPosition
    • *pop_*positionX
    • *pop_*positionY
    • *pop_*rotation
    • *pop_*rotationX
    • *pop_*rotationY
    • *pop_*scaleX
    • *pop_*scaleY
    • *pop_*scaleXY
    • *pop_*translationX
    • *pop_*translationXY
    • *pop_*translationY
    • *pop_*translationZ
    • *pop_*size
  • CAShapeLayer

    • strokeColor
    • strokeStart
    • strokeEnd
  • NSLayoutConstraint

    • constant
  • UIView (and subclasses)

    • alpha
    • backgroundColor
    • bounds
    • center
    • frame
    • *pop_*scaleX
    • *pop_*scaleY
    • *pop_*scaleXY
  • UIScrollView (and subclasses)

    • contentOffset
    • contentSize

License

POP+MCAnimate is under the MIT license.

More Repositories

1

Realm-JSON

A concise Mantle-like way of working with Realm and JSON.
Objective-C
663
star
2

JSONCodable

Hassle-free JSON encoding and decoding in Swift
Swift
602
star
3

MCPanelViewController

Drop-in panel control for iOS with blurring background and screen-edge activation gestures.
Objective-C
325
star
4

Fluent

Swift animation made easy
Swift
300
star
5

MCFireworksButton

Drop-in button control with with particle effects similar to the Like button in Facebook Paper.
Objective-C
233
star
6

Kaleidoscope

Writing a lexer and parser for Kaleidoscope in Swift
Swift
61
star
7

MCBlurredModalController

A sleek way to display your view controller modally.
Objective-C
61
star
8

Brotli

An iOS and OSX wrapper for Google's Brotli project.
C
47
star
9

MCNumberLabel

Drop-in label control with the ability to animate digits.
Objective-C
42
star
10

MCGraphView

A light-weight solution for displaying graphs.
Objective-C
19
star
11

MCNotificationManager

Show your own banners like Notification Center within your app.
Objective-C
17
star
12

MCModalView

UIAlertView/UIActionSheet replacement supporting iPhone/iPad and device rotations.
Objective-C
13
star
13

MCAppRouter

URL routing for iOS made simple.
Objective-C
10
star
14

Layout

Functional layout in Swift
Swift
9
star
15

MCBinaryHeap

An Objective-C wrapper of CFBinaryHeap. Core Foundation priority queue implementation.
Objective-C
9
star
16

MCDynamicObject

Automatic persistence for your next iOS project.
C
8
star
17

MCAdditions

A host of useful utilties for any iOS application.
Objective-C
6
star
18

MCObservation

Easy-to-use, fire-and-forget KVO and notifications.
Objective-C
5
star
19

MCTimeSeriesView

A light-weight solution for displaying time series charts.
Objective-C
5
star
20

JSONSerialization

Natively implemented JSON serialization in Swift
Swift
4
star
21

react-rebels

Flux simplified
JavaScript
2
star
22

polymorphism-with-protocols

Good API design is essential for writing code that scales. In this talk, we look at some characteristics of good design and how to refactor code using the protocol features in Swift.
Swift
2
star
23

react-kit

Boilerplate for project with React and Webpack.
JavaScript
2
star
24

amigo

Swift
1
star
25

Click

Easy window recording for macOS
Swift
1
star