Skip to content

Instantly share code, notes, and snippets.

@radianttap
Forked from anonymous/gist:4468522
Last active December 10, 2015 19:48
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radianttap/4484269 to your computer and use it in GitHub Desktop.
Save radianttap/4484269 to your computer and use it in GitHub Desktop.
Pulse view
+ (void)pulseView:(UIView *)view completion:(void (^)(void))block {
// if you use auto layout, view-based transform go haywire, as they trigger layoutSubviews
// consequence is that you have no idea where the view will end up on the screen once animation completes
// see this discussion: http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used
// thus (per solution 4 from link above), rewriting with CAKeyframeAnimation
CAKeyframeAnimation *ka = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
ka.duration = .49;
ka.keyTimes = @[@(.102), @(.347), @(.551), @(.735), @(.898), @(1.0)];
ka.values = @[
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0.7, 0.7))],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(1.25, 1.25))],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0.9, 0.9))],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(1.05, 1.05))],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0.95, 0.95))],
[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(1.0, 1.0))]
];
ka.removedOnCompletion = YES;
ka.repeatCount = 1;
ka.fillMode = kCAFillModeForwards;
ka.autoreverses = NO;
if (block == NULL) {
[view.layer addAnimation:ka forKey:@"transform"];
} else {
[CATransaction begin];
[CATransaction setCompletionBlock:block];
[view.layer addAnimation:ka forKey:@"transform"];
[CATransaction commit];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment