views:

388

answers:

1

I've looking to animate a a needle in a speedometer-like item. How do I spin the needle and simulate the acceleration and the bouncing effect you would see in cartoons (when the needle reaches the max and starts bouncing).

+1  A: 

The easiest way would be would be to have a UIImageView for the speedometer and use a CALayer for the needle (or the CALayer of a UIView).

You can set an anchor point on the needle and all rotation animations will occur relative to that. So obviously you want to set the anchor point to the base.

Then you need rotate the needle. Apply/modify the CATransform of the CALayer to rotate your needle.

The largest issue is how fast it accelerates and how to handle the bouncing. This is all math. You'll have to play with it and tweak it. A good start can be found here though:

http://watchingapple.com/2008/04/core-animation-creating-a-jack-in-the-box-with-cakeyframeanimation/

Corey Floyd
Great reference link, thanks.
Nathan de Vries