Created
March 27, 2013 03:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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