use this function - (void) shakeView: (UIView *) viewToShake and write down any animation code that you want in this function and call it from the place where you want to animate the element
and if you select the first animation, and then use the next part of the code, this function is used to properly animate
#define RADIANS(degrees) ((degrees * M_PI) / 180.0) - (void) wobbleEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { UIView* item = (__bridge UIView *)context; item.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(90.0)); }
and here are two types of animations chosen what you want
1. Shake the animation, for example, remove pp from the ipad or iphone and decide to shake it at the right angle
CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(88.0)); CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(92.0)); viewToShake.transform = leftWobble;
2. normal shaking animation
CGFloat t = 2.0; CGAffineTransform translateRight = CGAffineTransformTranslate(CGAffineTransformIdentity, 85, 0.0); CGAffineTransform translateLeft = CGAffineTransformTranslate(CGAffineTransformIdentity, 95, 0.0); viewToShake.transform = translateLeft; [UIView animateWithDuration:0.07 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{ [UIView setAnimationRepeatCount:2.0]; viewToShake.transform = translateRight; } completion:^(BOOL finished) { if (finished) { [UIView animateWithDuration:0.05 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ viewToShake.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 95, 0.0); } completion:NULL]; } }];
}
source share