Skip to content

Instantly share code, notes, and snippets.

@pronebird
Last active August 29, 2015 14:17
Show Gist options
  • Save pronebird/f62330a395712c41feaa to your computer and use it in GitHub Desktop.
Save pronebird/f62330a395712c41feaa to your computer and use it in GitHub Desktop.
//
// main.m
//
#import <UIKit/UIKit.h>
#import <pop/POP.h>
#import "AppDelegate.h"
static CGFloat deceleration_for_distance(CGFloat distance, CGFloat velocity)
{
if(distance == 0.0)
{
return 0.0;
}
if(velocity == 0.0)
{
return 0.0;
}
CGFloat acceleration = ((velocity * velocity)) / (distance * 2.0);
CGFloat deceleration = 1.0 / (abs(acceleration) / 1000.0);
return MIN(0.999, MAX(0.0, deceleration));
}
int main(int argc, char * argv[]) {
@autoreleasepool {
CGPoint initialPoint = CGPointMake(0, 0);
CGPoint finalPoint = CGPointMake(100, 0);
CGPoint velocity = CGPointMake(50, 0);
CGFloat distance = finalPoint.x - initialPoint.x;
CGFloat deceleration = deceleration_for_distance(distance, velocity.x);
POPDecayAnimation *decayAnimation = [POPDecayAnimation animation];
decayAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewCenter];
decayAnimation.fromValue = [NSValue valueWithCGPoint:initialPoint];
decayAnimation.deceleration = deceleration;
decayAnimation.velocity = [NSValue valueWithCGPoint:velocity];
[decayAnimation toValue];
NSLog(@"decay = %@", decayAnimation);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment