Hello friends,
Here we will learn how to add shaking animation to an UIView.
It’s just an CABasicAnimation,
CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@”transform.rotation”];
[anim setToValue:[NSNumber numberWithFloat:0.0f]]; [anim setFromValue:[NSNumber numberWithDouble:M_PI/30]]; // rotation angle [anim setDuration:0.1]; [anim setRepeatCount:NSUIntegerMax]; [anim setAutoreverses:YES]; [pressedImageView.layer addAnimation:anim forKey:@”iconShake”];In above code, pressedImageView is an UIImageview. This animation can be added to other UIView elements too.
You can adjust the rotation angle, by setting the proper value.
Hope this will be helpful to somebody.
Happy Coding…!!