IOS:指南针在我的应用程序中

时间:2013-06-21 08:41:55

标签: ios uiimageview compass-geolocation

我有这个代码在我的应用程序中插入指南针:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{

    // Convert Degree to Radian and move the needle
    float oldRad =  -manager.heading.trueHeading * M_PI / 180.0f;
    float newRad =  -newHeading.trueHeading * M_PI / 180.0f;
    CABasicAnimation *theAnimation;
    theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
    theAnimation.toValue=[NSNumber numberWithFloat:newRad];
    theAnimation.duration = 0.5f;
    [compassImage.layer addAnimation:theAnimation forKey:@"animateMyRotation"];
    compassImage.transform = CGAffineTransformMakeRotation(newRad);

}

它工作正常,但有时会发生指南针图像被修改而且看起来很紧张......我不知道问题是什么。 你能救我吗?

1 个答案:

答案 0 :(得分:0)

//Try this

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    //[manager stopUpdatingHeading];

    double rotation = newHeading.magneticHeading * 3.14159 / 180;

    [_compass_image setTransform:CGAffineTransformMakeRotation(-rotation)];
}