Created
February 21, 2012 18:59
-
-
Save nielsbot/1878153 to your computer and use it in GitHub Desktop.
Shake animation on UIView
This file contains 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
// this code will cause a UIView to shake--good for "login error" | |
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ; | |
anim.values = [ NSArray arrayWithObjects: | |
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ], | |
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f) ], | |
nil ] ; | |
anim.autoreverses = YES ; | |
anim.repeatCount = 2.0f ; | |
anim.duration = 0.07f ; | |
[ viewToShake.layer addAnimation:anim forKey:nil ] ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment