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

おっと...お時間いただき申し訳ありません:(問題が見つかりました..いつものように、エラーは星ではなく、私たち自身にあります

明らかにatanを使用する必要がある場合は、acos関数を使用します

于 2012-11-23T16:46:05.703 に答える