2

I have done the coding for rotating a needle in a compass using:

NeedleView.transform=CGAffineTransformMakeRotation(theHeading); 

but the rotation is not smooth. It is moving roughly.

Can anyone tell me how to do a smooth rotation of the compass needle with respect to angular movement?

sth
  • 222,467
  • 53
  • 283
  • 367
adhees
  • 79
  • 2
  • 5

3 Answers3

3

You can compensate the jumpiness of the compass with the gyroscope. I have done a project using that method that you can see here: http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/

Ellen S
  • 1,047
  • 1
  • 13
  • 18
1

Try this. Works well for me.

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
self.lblGrados.text = [NSString stringWithFormat:@"%.0f°", newHeading.magneticHeading];

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

needle.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI / 180);
    } completion:nil];


}
oscar castellon
  • 3,048
  • 30
  • 19
0

Do an animation with the transform, don't just set it. If you set it, it will change rotation right away. Animation will slow it. You can select the duration over which the animation occurs to slow it down. Look at the docs for UIView for the animation APIs.

David Neiss
  • 8,161
  • 2
  • 20
  • 21