Skip to content

Instantly share code, notes, and snippets.

Created May 22, 2012 16:40
Show Gist options
  • Save anonymous/2770147 to your computer and use it in GitHub Desktop.
Save anonymous/2770147 to your computer and use it in GitHub Desktop.
Wiggle Animation
- (void) addWiggleAnimationForView:(UIView*)someView
{
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
anim.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:-0.05],
[NSNumber numberWithFloat:0.05],
nil];
anim.duration = 0.09f + ((rand() % 10) * 0.01f);
anim.autoreverses = YES;
anim.repeatCount = FLT_MAX;
[someView.layer addAnimation:anim forKey:@"wiggleRotation"];
anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
anim.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:-1],
[NSNumber numberWithFloat:1],
nil];
anim.duration = 0.07f + ((rand() % 10) * 0.01f);
anim.autoreverses = YES;
anim.repeatCount = FLT_MAX;
anim.additive = YES;
[someView.layer addAnimation:anim forKey:@"wiggleTranslationY"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment