Shaking Animation of an UIView

 

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…!!


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box