Skip to content

Instantly share code, notes, and snippets.

@coryhymel
Created March 27, 2013 03:39
Show Gist options
  • Save coryhymel/5251418 to your computer and use it in GitHub Desktop.
Save coryhymel/5251418 to your computer and use it in GitHub Desktop.
A way to make any object to "shake". In this example we use a UILabel.
UILabel *myLabel....
CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
[shake setDuration:0.1];
[shake setRepeatCount:2];
[shake setAutoreverses:YES];
[shake setFromValue:[NSValue valueWithCGPoint:
CGPointMake(myLabel.center.x - 5,myLabel.center.y)]];
[shake setToValue:[NSValue valueWithCGPoint:
CGPointMake(myLabel.center.x + 5, myLabel.center.y)]];
[myLabel.layer addAnimation:shake forKey:@"position"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment