An extensible iOS and OS X animation library, useful for physics-based interactions.

Related tags

Animation pop
Overview

pop

Pop is an extensible animation engine for iOS, tvOS, and OS X. In addition to basic static animations, it supports spring and decay dynamic animations, making it useful for building realistic, physics-based interactions. The API allows quick integration with existing Objective-C or Swift codebases and enables the animation of any property on any object. It's a mature and well-tested framework that drives all the animations and transitions in Paper.

Build Status

Installation

Pop is available on CocoaPods. Just add the following to your project Podfile:

pod 'pop', '~> 1.0'

Bugs are first fixed in master and then made available via a designated release. If you tend to live on the bleeding edge, you can use Pop from master with the following Podfile entry:

pod 'pop', :git => 'https://github.com/facebook/pop.git'

Framework (manual)

By adding the project to your project and adding pop.embedded framework to the Embedded Binaries section on the General tab of your app's target, you can set up pop in seconds! This also enables @import pop syntax with header modules.

Note: because of some awkward limitations with Xcode, embedded binaries must share the same name as the module and must have .framework as an extension. This means that you'll see three pop.frameworks when adding embedded binaries (one for OS X, one for tvOS, and one for iOS). You'll need to be sure to add the right one; they appear identically in the list but note the list is populated in order of targets. You can verify the correct one was chosen by checking the path next to the framework listed, in the format <configuration>-<platform> (e.g. Debug-iphoneos).

Embedded Binaries

Note 2: this method does not currently play nicely with workspaces. Since targets can only depend on and embed products from other targets in the same project, it only works when pop.xcodeproj is added as a subproject to the current target's project. Otherwise, you'll need to manually set the build ordering in the scheme and copy in the product.

Static Library (manual)

Alternatively, you can add the project to your workspace and adopt the provided configuration files or manually copy the files under the pop subdirectory into your project. If installing manually, ensure the C++ standard library is also linked by including -lc++ to your project linker flags.

Usage

Pop adopts the Core Animation explicit animation programming model. Use by including the following import:

Objective-C

#import <pop/POP.h>

or if you're using the embedded framework:

@import pop;

Swift

import pop

Start, Stop & Update

To start an animation, add it to the object you wish to animate:

Objective-C

POPSpringAnimation *anim = [POPSpringAnimation animation];
...
[layer pop_addAnimation:anim forKey:@"myKey"];

Swift

let anim = POPSpringAnimation()
...
layer.pop_add(anim, forKey: "myKey")

To stop an animation, remove it from the object referencing the key specified on start:

Objective-C

[layer pop_removeAnimationForKey:@"myKey"];

Swift

layer.pop_removeAnimation(forKey: "myKey")

The key can also be used to query for the existence of an animation. Updating the toValue of a running animation can provide the most seamless way to change course:

Objective-C

anim = [layer pop_animationForKey:@"myKey"];
if (anim) {
  /* update to value to new destination */
  anim.toValue = @(42.0);
} else {
  /* create and start a new animation */
  ....
}

Swift

if let anim = layer.pop_animation(forKey: "myKey") as? POPSpringAnimation {
    /* update to value to new destination */
    anim.toValue = 42.0
} else {
    /* create and start a new animation */
    ....
}

While a layer was used in the above examples, the Pop interface is implemented as a category addition on NSObject. Any NSObject or subclass can be animated.

Types

There are four concrete animation types: spring, decay, basic and custom.

Spring animations can be used to give objects a delightful bounce. In this example, we use a spring animation to animate a layer's bounds from its current value to (0, 0, 400, 400):

Objective-C

POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 400, 400)];
[layer pop_addAnimation:anim forKey:@"size"];

Swift

if let anim = POPSpringAnimation(propertyNamed: kPOPLayerBounds) {
    anim.toValue = NSValue(cgRect: CGRect(x: 0, y: 0, width: 400, height: 400))
    layer.pop_add(anim, forKey: "size")
}

Decay animations can be used to gradually slow an object to a halt. In this example, we decay a layer's positionX from it's current value and velocity 1000pts per second:

Objective-C

POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim.velocity = @(1000.);
[layer pop_addAnimation:anim forKey:@"slide"];

Swift

if let anim = POPDecayAnimation(propertyNamed: kPOPLayerPositionX) {
    anim.velocity = 1000.0
    layer.pop_add(anim, forKey: "slide")
}

Basic animations can be used to interpolate values over a specified time period. To use an ease-in ease-out animation to animate a view's alpha from 0.0 to 1.0 over the default duration:

Objective-C

POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.fromValue = @(0.0);
anim.toValue = @(1.0);
[view pop_addAnimation:anim forKey:@"fade"];

Swift

if let anim = POPBasicAnimation(propertyNamed: kPOPViewAlpha) {
    anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    anim.fromValue = 0.0
    anim.toValue = 1.0
    view.pop_add(anim, forKey: "fade")
}

POPCustomAnimation makes creating custom animations and transitions easier by handling CADisplayLink and associated time-step management. See header for more details.

Properties

The property animated is specified by the POPAnimatableProperty class. In this example we create a spring animation and explicitly set the animatable property corresponding to -[CALayer bounds]:

Objective-C

POPSpringAnimation *anim = [POPSpringAnimation animation];
anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];

Swift

let anim = POPSpringAnimation()
if let property = POPAnimatableProperty.property(withName: kPOPLayerBounds) as? POPAnimatableProperty {
    anim.property = property
}

The framework provides many common layer and view animatable properties out of box. You can animate a custom property by creating a new instance of the class. In this example, we declare a custom volume property:

Objective-C

prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop) {
  // read value
  prop.readBlock = ^(id obj, CGFloat values[]) {
    values[0] = [obj volume];
  };
  // write value
  prop.writeBlock = ^(id obj, const CGFloat values[]) {
    [obj setVolume:values[0]];
  };
  // dynamics threshold
  prop.threshold = 0.01;
}];

anim.property = prop;

Swift

if let prop = POPAnimatableProperty.property(withName: "com.foo.radio.volume", initializer: { prop in
    guard let prop = prop else {
        return
    }
    // read value
    prop.readBlock = { obj, values in
        guard let obj = obj as? Volumeable, let values = values else {
            return
        }

        values[0] = obj.volume
    }
    // write value
    prop.writeBlock = { obj, values in
        guard var obj = obj as? Volumeable, let values = values else {
            return
        }

        obj.volume = values[0]
    }
    // dynamics threshold
    prop.threshold = 0.01
}) as? POPAnimatableProperty {
    anim.property = prop
}

For a complete listing of provided animatable properties, as well more information on declaring custom properties see POPAnimatableProperty.h.

Debugging

Here are a few tips when debugging. Pop obeys the Simulator's Toggle Slow Animations setting. Try enabling it to slow down animations and more easily observe interactions.

Consider naming your animations. This will allow you to more easily identify them when referencing them, either via logging or in the debugger:

Objective-C

anim.name = @"springOpen";

Swift

anim.name = "springOpen"

Each animation comes with an associated tracer. The tracer allows you to record all animation-related events, in a fast and efficient manner, allowing you to query and analyze them after animation completion. The below example starts the tracer and configures it to log all events on animation completion:

Objective-C

POPAnimationTracer *tracer = anim.tracer;
tracer.shouldLogAndResetOnCompletion = YES;
[tracer start];

Swift

if let tracer = anim.tracer {
    tracer.shouldLogAndResetOnCompletion = true
    tracer.start()
}

See POPAnimationTracer.h for more details.

Testing

Pop has extensive unit test coverage. To install test dependencies, navigate to the root pop directory and type:

pod install

Assuming CocoaPods is installed, this will include the necessary OCMock dependency to the unit test targets.

SceneKit

Due to SceneKit requiring iOS 8 and OS X 10.9, POP's SceneKit extensions aren't provided out of box. Unfortunately, weakly linked frameworks cannot be used due to issues mentioned in the Xcode 6.1 Release Notes.

To remedy this, you can easily opt-in to use SceneKit! Simply add this to the Preprocessor Macros section of your Xcode Project:

POP_USE_SCENEKIT=1

Resources

A collection of links to external resources that may prove valuable:

Contributing

See the CONTRIBUTING file for how to help out.

License

Pop is released under a BSD License. See LICENSE file for details.

Comments
  • Simulate display link with timer if display link creation failed.

    Simulate display link with timer if display link creation failed.

    Typically if no display is attached, the creation of display link will failed miserably. Since I use POP to animate custom properties that are not related to visual effects (sound volume ramps), I need to simulate a VBL.

    CLA Signed 
    opened by jcbertin 21
  • Single frame flashes of 'initial' animation before `fromValue` kicks in.

    Single frame flashes of 'initial' animation before `fromValue` kicks in.

    https://github.com/zdavison/POPBug/tree/master

    I've isolated a demonstrable version of this code here, with a short (shaky) vine you can view to see the bug. A few things I've noted:

    • The 'add' animation is the only time this occurs. This leads me to believe it may be because we're adding a new layer and immediately animating it. I have also seen this with existing layers though.
    • I've seen this behaviour with both scaling from 0, using transforms, and while animating bounds properties from CGRectZero.
    • It's intermittent, you may need to try playing with it to catch it. It also seems to only happen on my device, rather than the simulator. (Have tried on several iPads, mini, air, etc)

    This could also be my own bad usage / misunderstanding, which would be great!

    bug 
    opened by zdavison 20
  • Excessive calls to layoutSubviews?

    Excessive calls to layoutSubviews?

    I am getting this log when running this code http://pastie.org/9363482

    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MySubview
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    layoutSubviews in MyView
    viewDidLayoutSubviews in MyViewController
    

    etc etc...

    I can't really see how it is necessary to perform update the layout. It is a simple scale using transform on a subview. Is this by design?

    opened by hfossli 18
  • Importing <POP/POP.h> into the Swift bridging header does not seem to work

    Importing into the Swift bridging header does not seem to work

    When I put #import <POP/POP.h> in my SwiftBridge.h, I can't seem to reference any POP classes within my .swift files. Strangely, my target builds successfully despite many errors indicating Use of undeclared type 'POP Class' (with POP Class being a POP class of course).

    • The same things happens on both Xcode 6 beta and Xcode 6 beta 2.
    • The pop.xcodeproj is a sub-project inside of my own project
    • POP is useable in Objective-C, but not in Swift
    • Other headers I import in my SwiftBridge.h file can be used in Swift perfectly fine
    • In both my project and target's Build Settings, I have User Header Search Paths set to find the POP headers and Always Search User Paths to Yes. Framework Search Paths and Library Search Paths both have nothing in them.
    • SwiftBridge.h is correctly set under Build Settings as the Objective-C Bridging Header and Install Objective-C Compatibility Header is set to Yes.
    • My project's target has its Other Linker Flags set to -lc++ -all_load -ObjC.
    • The pop static library target is inside my target's Target Dependencies and the libpop.a is under Link Binary With Libraries.

    Need any other information, just have to ask! :)

    Thank you!

    opened by aleclarson 14
  • Can't build POP on a case sensitive file system

    Can't build POP on a case sensitive file system

    Hey,

    I can't build my projects with cocoa pods For instance AGGeometryKit+POP,I keep getting the error:

    .../AGGeometryKit-POP/Demo/Pods/pop/pop/POPAnimationExtras.h:12:9: 'POP/POPDefines.h' file not found

    In addition, it looks like you are using inconsistently internal imports "...h" and library imports <...h>

    For instance

    import <POP/POPDefines.h> in POPLayerExtras.h

    and

    import "POPDefines.h" in PopCGUtils.h

    Thanks ahead,

    Stéphane

    /cc @orta

    opened by slizeray 14
  • Why doesn't POPDecayAnimation use toValue?

    Why doesn't POPDecayAnimation use toValue?

    I noticed that POPDecayAnimation ignores the toValue property when set (fromValue works great). Why is this?

    If, for example, I'm using POPDecayAnimation to animate an X or Y position, what would be the appropriate way to have my object animate to a specific coordinate?

    opened by callmeed 14
  • Parameter 'The' not found in the function declaration

    Parameter 'The' not found in the function declaration

    This is not a big problem but a problem nevertheless. As you can see in the screenshot bellow, Xcode 8.3.2 is throwing a warning when compiling the latest version of pop. It would be really nice if this could be fixed so that the warning goes away. This happens in POPAnimation.h.

    screen shot 2017-05-08 at 17 20 57
    opened by zeusent 12
  • improve runtime check of properties attributes.

    improve runtime check of properties attributes.

    improve runtime check of properties attributes. But, it can't be merge like this. In the method to add/remove animation, i was thinking that "key" was the key for (KVC) to use with the object, but it might be not ... for exemple, in the unit test, a key "hello".

    opened by leverdeterre 12
  • Spring with kPOPLayerScaleXY flips the image of UIImageView

    Spring with kPOPLayerScaleXY flips the image of UIImageView

    Weird thing is it only flips for the very first time when I triggered this animation. Here is my code when UIImageView is tapped:

    - (void)buttonTapped:(id)sender
    {
        id object = [sender view];
    
        POPSpringAnimation *spring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
        spring.fromValue = [NSValue valueWithCGSize:CGSizeMake(0.8, 0.8)];
        spring.toValue = [NSValue valueWithCGSize:CGSizeMake(1, 1)];
        spring.springBounciness = 10;
        spring.springSpeed = 20;
        [object pop_addAnimation:spring forKey:@"anything"];
    }
    
    opened by JmeHsieh 12
  • NSCopying

    NSCopying

    I see that POPAnimations do not conform to NSCopying. I don't know enough about POP to say for certain, but I use relative additive Core Animation to get a similar effect as POP, and copying is a critical technique that might also be useful here.

    If layers are already animating along a complicated path due to continuous user interaction, and you want to insert new layers with animated values that exactly match existing ones, copying is one way to accomplish this.

    enhancement 
    opened by KevinDoughty 12
  • POPSpringAnimation acting weird on ios8+

    POPSpringAnimation acting weird on ios8+

    I am using POPSpringAnimation in order to show PickerView with bounce effect animation and hide it.

    I am using 2 methods show/hide. I made that app which works ios7 fine, But in iOS8, when user tap to select pickerView element following delegation method fired and sets text on label as expected.

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

    But showing animation broken as soon as user selects row. And PickerView view has disappeared. I put breakpoint in every method in implementation but breakpoint doesn't call any hide animation method.

    I really don't get it. Is there anyone who faced that problem ?

    opened by onderozcan 10
  • Add CodeTriage badge to facebook/pop

    Add CodeTriage badge to facebook/pop

    Adds a badge showing the number of people helping this repo on CodeTriage.

    Open Source Helpers

    What is CodeTriage?

    CodeTriage is an Open Source app that is designed to make contributing to Open Source projects easier. It works by sending subscribers a few open issues in their inbox. If subscribers get busy, there is an algorithm that backs off issue load so they do not get overwhelmed

    Read more about the CodeTriage project.

    Why am I getting this PR?

    Your project was picked by the human, @schneems. They selected it from the projects submitted to https://www.codetriage.com and hand edited the PR. How did your project get added to CodeTriage? Roughly about 3 years ago, Farteen added this project to CodeTriage in order to start contributing. Since then, 2 people have subscribed to help this repo.

    What does adding a badge accomplish?

    Adding a badge invites people to help contribute to your project. It also lets developers know that others are invested in the longterm success and maintainability of the project.

    You can see an example of a CodeTriage badge on these popular OSS READMEs:

    • Email clients like GMAIL do not render SVG images https://github.com/rails/rails
    • Email clients like GMAIL do not render SVG images https://github.com/crystal-lang/crystal

    Have a question or comment?

    While I am a bot, this PR was manually reviewed and monitored by a human - @schneems. My job is writing commit messages and handling PR logistics.

    If you have any questions, you can reply back to this PR and they will be answered by @schneems. If you do not want a badge right now, no worries, close the PR, you will not hear from me again.

    Thanks for making your project Open Source! Any feedback is greatly appreciated.

    opened by codetriage-readme-bot 1
  • Adding Code of Conduct file

    Adding Code of Conduct file

    This is pull request was created automatically because we noticed your project was missing a Code of Conduct file.

    Code of Conduct files facilitate respectful and constructive communities by establishing expected behaviors for project contributors.

    This PR was crafted with love by Facebook's Open Source Team.

    CLA Signed 
    opened by facebook-github-bot 0
  • POPSpringAnimation removedOnCompletion not working

    POPSpringAnimation removedOnCompletion not working

    After adding a POPSpringAnimation to a UIImageView, I expect the animation can remove itself but i did not, even use pop_removeAllAnimations the result same as before.

    opened by menttofly 0
Releases(1.0.11)
Owner
Meta Archive
These projects have been archived and are generally unsupported, but are still available to view and use
Meta Archive
Physics-based animations for iOS, tvOS, and macOS.

Advance An animation library for iOS, tvOS, and macOS that uses physics-based animations (including springs) to power interactions that move and respo

Tim Donnelly 4.5k Dec 29, 2022
A library of custom iOS View Controller Animations and Interactions.

RZTransitions is a library to help make iOS7 custom View Controller transitions slick and simple. Installation CocoaPods (Recommended) Add the followi

Rightpoint 1.9k Nov 20, 2022
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Simple, extensible interpolation framework

THIS PROJECT IS NO LONGER MAINTAINED. Popsicle is a Swift framework for creating and managing interpolations of different value types with built-in UI

David Roman 1.1k Nov 17, 2022
Designed for gesture-driven animations. Fast, simple, & extensible!

Yet Another Animation Library Designed for gesture-driven animations. Fast, simple, & extensible! It is written in pure swift 3.1 with protocol orient

Luke Zhao 509 Dec 21, 2022
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Simple Interface Core Animation Sica can execute various animations sequentially or parallelly. Features Animation with duration and delay parallel /

CATS Open Source Softwares 1k Nov 10, 2022
An experiment for using SwiftUI's custom timing Animation to create an orbital-like animation.

Orbital-SwiftUI-Animation An experiment for using SwiftUI's custom timing curve to create an orbital-like animation. How it looks: How it works: Apply

Mostafa Abdellateef 7 Jan 2, 2023
Anima is chainable Layer-Based Animation library for Swift5.

Anima Anima is chainable Layer-Based Animation library for Swift5. It support to make sequensial and grouped animation more easily. is written as foll

Satoshi Nagasaka 528 Dec 27, 2022
Gemini is rich scroll based animation framework for iOS, written in Swift.

Overview What is the Gemini? Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which

Shohei Yokoyama 3k Dec 27, 2022
Wave is a spring-based animation engine for iOS that makes it easy to create fluid, interruptible animations that feel great.

Wave is a spring-based animation engine for iOS and iPadOS. It makes it easy to create fluid, interactive, and interruptible animations that feel great.

Janum Trivedi 1.2k Jan 8, 2023
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.

LoadingShimmer An easy way to add a shimmering effect to any view with just single line of code. It is useful as an unobtrusive loading indicator. Thi

Jogendra 1.4k Jan 6, 2023
Swift animation library for iOS, tvOS and macOS.

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.bo

Onur Ersel 555 Dec 12, 2022
A powerful, elegant, and modular animation library for Swift.

MotionMachine provides a modular, powerful, and generic platform for manipulating values, whether that be animating UI elements or interpolating prope

Brett Walker 387 Dec 9, 2022
Easy animation library on iOS with Swift2

Cheetah Cheetah is an animation utility on iOS with Swift. Cheetah can animate any properties since Cheetah uses simple CADisplayLink run loop to chan

Suguru Namura 592 Dec 6, 2022
A radical & elegant animation library for iOS.

Installation • Usage • Debugging • Animatable Properties • License Dance is a powerful and straightforward animation framework built upon the new UIVi

Saoud Rizwan 648 Dec 14, 2022
Animation library for iOS in Swift

TweenKit TweenKit is a powerful animation library that allows you to animate (or 'tween') anything. TweenKit's animations are also scrubbable, perfect

Steve Barnegren 1.3k Dec 18, 2022
This library is for adding animation to iOS tabbar items, which is inherited from UITabBarController.

This library is for adding animation to iOS tabbar items, which is inherited from UITabBarController. Installation Just add the Sources folder to your

Yuşa Doğru 162 Jan 6, 2023