0

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

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

}

它工作正常,但有时会发生罗盘图像被修改并且似乎被拉伸......我不知道是什么问题。你能帮助我吗?

4

1 回答 1

0
//Try this

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

    double rotation = newHeading.magneticHeading * 3.14159 / 180;

    [_compass_image setTransform:CGAffineTransformMakeRotation(-rotation)];
}
于 2013-06-21T08:57:17.053 回答