title: UIView shake animation
body: <p>i'm trying to make a UIView shake when a button is pressed.</p>
  
  <p>I am adapting the code I found on <a href="http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/">http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/</a>.</p>
  
  <p>However, by trying to adapt the following code to shake a UIView, it does not work:</p>
  
  <pre><code>- (void)animate {
      const int numberOfShakes = 8;
      const float durationOfShake = 0.5f;
      const float vigourOfShake = 0.1f;
  
      CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];
  
      CGRect frame = lockView.frame;
  
      CGMutablePathRef shakePath = CGPathCreateMutable();
      CGPathMoveToPoint(shakePath, NULL, CGRectGetMinX(frame), CGRectGetMinY(frame));
  
      for (int index = 0; index &lt; numberOfShakes; ++index) {
          CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) - frame.size.width * vigourOfShake, CGRectGetMinY(frame));
  
          CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) + frame.size.width * vigourOfShake, CGRectGetMinY(frame));
      }
  
      CGPathCloseSubpath(shakePath);
  
      shakeAnimation.path = shakePath;
      shakeAnimation.duration = durationOfShake;
  
  
      [lockView.layer addAnimation:shakeAnimation forKey:@"frameOrigin"];
  
  }
  </code></pre>