title: how to create iphone's wobbling icon effect?
body: <p>I want to wobble an image back and forth in my application similar to how the iPhone icons wobble when you press down on it.  What's the best way to do that?  </p>
  
  <p>This is my first foray into animations that's not using an animated GIF.  I think the idea is to slightly rotate the image back and forth to create the wobbling effect.  I've looked at using CABasicAnimation and CAKeyframeAnimation.  CABasicAnimation creates a jitter every time it repeats because it jumps to the from position and doesn't interpolate back.  CAKeyframeAnimation seems like the solution except that I can't get it to work.  I must be missing something.  Here's my code using the CAKeyframeAnimation (which doesn't work):</p>
  
  <pre><code>    NSString *keypath = @"wobbleImage";
  CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:keypath];
  animation.duration = 1.0f;
  animation.delegate = self;
  animation.repeatCount = 5;
  
  CGFloat wobbleAngle = 0.0872664626f;
  NSValue *initial = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 0.0f, 1.0f)];
  NSValue *middle = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(wobbleAngle, 0.0f, 0.0f, 1.0f)];
  NSValue *final = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-wobbleAngle, 0.0f, 0.0f, 1.0f)];
  animation.values = [NSArray arrayWithObjects:initial, middle, final, nil];
  
  [imageView.layer addAnimation:animation forKey:keypath];
  </code></pre>
  
  <p><br />
  Or there could be a totally simpler solution that I'm just missing.  Appreciate any pointers.  Thanks!</p>