In my xcode project I have an UIImage. I want to make it shaking (animation) from left to right a little bit. I wrote this code, however, its not working.
-(void
Here's the code I use for that effect.
-(void)shakeView {
CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
[shake setDuration:0.1];
[shake setRepeatCount:2];
[shake setAutoreverses:YES];
[shake setFromValue:[NSValue valueWithCGPoint:
CGPointMake(lockImage.center.x - 5,lockImage.center.y)]];
[shake setToValue:[NSValue valueWithCGPoint:
CGPointMake(lockImage.center.x + 5, lockImage.center.y)]];
[lockImage.layer addAnimation:shake forKey:@"position"];
}
As Jere
mentioned. Make sure to include the import:
#import
You can also add it as a category on UIView
.