0

我正在开发一个地图应用程序。我在地图上画了一条动画线,然后使用应该在这条线上绘制的图像(标尺图像)。为了画线,我使用带有路径的 CABasicAnimation:



    -(void)lineaAnimation {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
        animation.duration = animDuration;
        animation.delegate=self;
        animation.repeatCount = 0;
        animation.autoreverses = NO;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.fromValue = (id)inip;
        animation.toValue = (id)finp;
        animation.fillMode=kCAFillModeForwards;
        animation.removedOnCompletion=NO;
        [shapeLayer addAnimation:animation forKey:@"animatePath"];
    }

    -(void)linea:(CGPoint)origen to:(CGPoint)destino animado:(BOOL)anim duracion:(float)durac inicio:(float)delay {
        inip    = CGPathCreateMutable();
        finp    = CGPathCreateMutable();

        CGPathMoveToPoint(inip, nil, origen.x, origen.y);
        CGPathAddLineToPoint(inip, nil, origen.x, origen.y);
        CGPathCloseSubpath(inip);

        CGPathMoveToPoint(finp, nil, origen.x, origen.y);
        CGPathAddLineToPoint(finp, nil, destino.x, destino.y);
        CGPathCloseSubpath(finp);

        rootLayer   = [CALayer layer];
        rootLayer.frame = fondo.bounds;
        [fondo.layer addSublayer:rootLayer];

        shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = inip;
        UIColor *fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
        shapeLayer.fillColor = fillColor.CGColor;
        UIColor *strokeColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
        shapeLayer.strokeColor = strokeColor.CGColor;
        shapeLayer.lineWidth = 5.0;
        shapeLayer.fillRule = kCAFillRuleEvenOdd;
        [morrallaLayer addObject:shapeLayer];
        [rootLayer addSublayer:shapeLayer];
        animDuration=durac;
        [self performSelector:@selector(lineaAnimation) withObject:nil afterDelay:delay];
    }

然后我尝试将规则的中心移动到该点并使用以下代码旋转标尺图像:



    delta=acos((destino.y-origen.y)/(destino.x-origen.x));
    giroIni=0.0;
    giroFin=delta;
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.fromValue= [NSNumber numberWithFloat:giroIni];
    animation.toValue= [NSNumber numberWithFloat:giroFin];
    animation.delegate = self;
    animation.repeatCount = 0;
    animation.autoreverses = NO;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.duration = animDuration;
    animation.fillMode=kCAFillModeForwards;
    animation.removedOnCompletion=NO;
    [ruleL addAnimation:animation forKey:@"giroAngulo"];

问题是标尺边界线与画线不匹配,根据最终方向的不同,存在一定程度的差异......为什么?非常感谢!

4

1 回答 1

0

Ooooops... sorry for your time :( I found the problem and.. as usual the error is not in the stars but in ourselves

I use the acos function when OBVIOUSLY I should use atan

于 2012-11-23T16:46:05.703 回答