Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #import "UIView+Bounce.h"
 - @implementation UIView (Bounce)
 - + (CAKeyframeAnimation *)dockBounceAnimationWithViewHeight:(CGFloat)viewHeight {
 - NSUInteger const kNumFactors = 23;
 - CGFloat const kFactorsPerSec = 120.0f;
 - CGFloat const kFactorsMaxValue = 128.0f;
 - CGFloat factors[kNumFactors] = { 0, 83, 100, 114, 124, 138, 156, 184, 156, 138, 124, 114, 100, 83, 32, 0, 0, 18, 28, 32, 28, 18, 0 };
 - NSMutableArray *transforms = [NSMutableArray array];
 - for (NSUInteger i = 0; i < kNumFactors; i++) {
 - CGFloat positionOffset = factors[i] / kFactorsMaxValue * viewHeight;
 - CATransform3D transform = CATransform3DMakeTranslation(0.0f, -positionOffset, 0.0f);
 - [transforms addObject:[NSValue valueWithCATransform3D:transform]];
 - }
 - CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
 - animation.repeatCount = 1;
 - animation.duration = kNumFactors * 1.0f / kFactorsPerSec;
 - animation.fillMode = kCAFillModeForwards;
 - animation.values = transforms;
 - animation.removedOnCompletion = YES; // final stage is equal to starting stage
 - animation.autoreverses = NO;
 - return animation;
 - }
 - - (void)bounce:(float)bounceFactor {
 - CGFloat midHeight = self.frame.size.height * bounceFactor;
 - CAKeyframeAnimation *animation = [[self class] dockBounceAnimationWithViewHeight:midHeight];
 - [self.layer addAnimation:animation forKey:@"bouncing"];
 - }
 - @end
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment