Last active
August 29, 2015 14:00
-
-
Save rounak/105a93774fef45104c8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get velocity from pan gesture | |
CGPoint velocity = [panGestureRecognizer velocityInView:self]; | |
if (self.bounds.size.width >= self.contentSize.width) { | |
//make movement zero along x if no horizontal scrolling | |
velocity.x = 0; | |
} | |
if (self.bounds.size.height >= self.contentSize.height) { | |
//make movement zero along y if no vertical scrolling | |
velocity.y = 0; | |
} | |
//we need the negative velocity of what we get from the pan gesture, so flip the signs | |
velocity.x = -velocity.x; | |
velocity.y = -velocity.y; | |
POPDecayAnimation *decayAnimation = [POPDecayAnimation animation]; | |
POPAnimatableProperty *prop = [POPAnimatableProperty propertyWithName:@"com.rounak.boundsY" initializer:^(POPMutableAnimatableProperty *prop) { | |
// read value, feed data to Pop | |
prop.readBlock = ^(id obj, CGFloat values[]) { | |
values[0] = [obj bounds].origin.x; | |
values[1] = [obj bounds].origin.y; | |
}; | |
// write value, get data from Pop, and apply it to the view | |
prop.writeBlock = ^(id obj, const CGFloat values[]) { | |
CGRect tempBounds = [obj bounds]; | |
tempBounds.origin.x = values[0]; | |
tempBounds.origin.y = values[1]; | |
[obj setBounds:tempBounds]; | |
}; | |
// dynamics threshold | |
prop.threshold = 0.01; | |
}]; | |
decayAnimation.property = prop; | |
decayAnimation.velocity = [NSValue valueWithCGPoint:velocity]; | |
[self pop_addAnimation:decayAnimation forKey:@"decelerate"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment