How can I add a bounce effect when I am about to show an UIImageView as a subview? Do I have to use CoreAnimation to do this? My only guess right now is to use CAKeyframeAnimation, please let me know if there's a better way. Here's my current code:
CABasicAnimation * theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
theAnimation.delegate = self;
theAnimation.duration = 1.0;
theAnimation.fromValue = [NSNumber numberWithFloat:notif.center.y];
theAnimation.toValue = [NSNumber numberWithFloat:notif.center.y-20];
theAnimation.repeatCount = 3;
y-axis animation using CABasicAnimation:
If you want to implement shrink and grow you have to add a CGAffineTransformMakeScale, eg:
@Jano's answer in Swift
Play with the values to get different effects.
Bouncy (expand/shrink) animation in Swift:
If
imageView
is correctly added to the view as a subview, toggling betweenselected = false
toselected = true
should swap the image with a bouncy animation.SNStockCellSelectionAccessoryViewImage
just returns a different image based on the current selection state, see below:The GIF example below is a bit slowed down, the actual animation happens faster: