如何顺利旋转罗盘针

时间:2011-05-09 11:44:33

标签: iphone xcode compass-geolocation

我已经完成了使用以下方法在指南针中旋转针的编码:

NeedleView.transform=CGAffineTransformMakeRotation(theHeading); 

但旋转不顺畅。它正在大致移动。

有谁能告诉我如何在角度运动方面顺利旋转罗盘针?

3 个答案:

答案 0 :(得分:3)

您可以使用陀螺仪补偿指南针的跳跃性。我已经使用您可以在此处看到的方法完成了一个项目:http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/

答案 1 :(得分:1)

试试这个。适合我。

- (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];


}

答案 2 :(得分:0)

使用变换做动画,不要只是设置它。如果你设置它,它会立即改变旋转。动画会减慢它。您可以选择动画发生的持续时间以减慢动画的速度。查看动画API的UIView文档。

相关问题