tags:

views:

187

answers:

2

I have implemented speedometer i have one arrow image.i want to rotate 0 to 180 very smoothly.how it possible?

+1  A: 

Does 'speedometer' means accelerometer?

Use UIAccelerometer to get accelerometer datas. Then get the actual movement data with filter. Then transform them to angles. These three steps can be found in UIAccelerometer's official examples.

Use CGAffineTransform to rotate the image view. This won't be hard I think. But I have no idea about this.

Mike Chen
No, spedometer means spedometer, which is a gauge used to dislay speed, most typically found in cars.
Bogatyr
A: 

I just wrote an iPhone app that displays a spedometer. Here's the code that animates movement of the needle image:

CABasicAnimation *rotateAnimation = [CABasicAnimation animation];
rotateAnimation.keyPath = @"transform.rotation.z";
rotateAnimation.fromValue = [NSNumber numberWithFloat:DegreesToRadians( self.needleAngle )];
rotateAnimation.toValue = [NSNumber numberWithFloat:DegreesToRadians( newNeedleAngle )];
rotateAnimation.duration = 1.5;
rotateAnimation.removedOnCompletion = NO;
// leaves presentation layer in final state; preventing snap-back to original state
//
rotateAnimation.fillMode = kCAFillModeBoth; 
rotateAnimation.repeatCount = 0;
rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// Add the animation to the selection layer. This causes it to begin animating. 
//
[self.needleIV.layer addAnimation:rotateAnimation forKey:@"rotateAnimation"];

The "removedOnCompletion = NO" is important for the needle not to snap back to its starting position once the animation completes.

Bogatyr