2012-11-22 60 views
0

我正在開發地圖應用程序。我在地圖上繪製了一條動畫線,然後使用應該在線上繪製的圖像(標尺圖像)。爲了吸引我用路徑的CABasicAnimation行:使用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"]; 

的問題是標尺邊界不符合線條繪製,取決於最終方向有一定程度的差異...爲什麼? 非常感謝!

回答

0

Ooooops ...對不起您的時間:( 我發現這個問題,並..像往常一樣的錯誤不在星星,但對自己

我使用ACOS功能時,很顯然,我應該ATAN

使用