Animar um UIView ao longo de um arco
Desejo animar uma vista ao longo de um arco, como mostrado na imagem da posição 1 para a posição 2.
O que realmente acontece é que a animação da vista descreve um círculo completo em vez de um arco. Minhas perguntas são:
Eu deveria estar usandoCGPathAddArc ouCGPathAddArcToPoint ?Eu preciso usarCGPathMoveToPoint para descrever a localização inicial da visão ou não?Quando percorro o código, os valores de CGPoints são como espero que sejam, assim como os ângulos.
Eu uso a seguinte função para obter CGPoints em um círculo
CGPoint pointOnCircle(CGPoint centre, float radius, float angle)
{
float x = centre.x + radius * cosf(angle);
float y = centre.y + radius * sinf(angle);
return CGPointMake(x, y);
}
Estou usando o seguinte código e variantes, mas ainda não consegui decifrá-lo.
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = duration;
pathAnimation.repeatCount = 1;
CGPoint viewCenter = dynamicView.objectCenter;
CGMutablePathRef arcPath = CGPathCreateMutable();
// CGPathMoveToPoint(arcPath, NULL, viewCenter.x, viewCenter.y);
//work out the half way point
float halfwayAngle = dynamicView.angle + (0.5f * self.angleIncrement);
float fullwayAngle = dynamicView.angle + self.angleIncrement;
CGPoint halfwayPoint = pointOnCircle(self.center, self.radius, halfwayAngle);
CGPoint fullwayPoint = pointOnCircle(self.center, self.radius, fullwayAngle);
CGPathAddArc(arcPath, NULL, halfwayPoint.x, halfwayPoint.y, self.radius, dynamicView.angle, fullwayAngle, clockwise);
// CGPathAddArcToPoint(arcPath, NULL, viewCenter.x, viewCenter.y, fullwayPoint.x, fullwayPoint.y, self.radius);
pathAnimation.path = arcPath;
CGPathRelease(arcPath);
[dynamicView.layer addAnimation:pathAnimation forKey:@"arc"];