You can use a CABasicAnimation, and set the repeat count to some small value, while animating the position of the view.layer that you want to vibrate. Note that clipsToBounds
for the view must be set to NO. Also be sure to include the QuartzCore framework in the project.
- (void)shakeView:(UIView *)view
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.x"];
animation.duration = 0.1;
animation.byValue = @(20);
animation.autoreverses = YES;
animation.repeatCount = 10;
[view.layer addAnimation:animation forKey:@"Shake"];
}