【问题标题】:IOS: compass in my appIOS:我的应用程序中的指南针
【发布时间】:2013-06-21 08:41:55
【问题描述】:

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

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

}

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

【问题讨论】:

    标签: ios uiimageview compass-geolocation


    【解决方案1】:
    //Try this
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {
        //[manager stopUpdatingHeading];
    
        double rotation = newHeading.magneticHeading * 3.14159 / 180;
    
        [_compass_image setTransform:CGAffineTransformMakeRotation(-rotation)];
    }
    

    【讨论】:

    • 我试过但我评论了“[manager stopUpdatingHeading]”否则没有动画;但是它似乎工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    相关资源
    最近更新 更多