2

나는 예를 들어 나는이 방법 선 그린, 그려진 오브젝트 애니메이션을 위해 노력하고 있어요 :Objective C에서 그려진 선을 애니메이트하는 방법은 무엇입니까?

UIBezierPath *path = [UIBezierPath bezierPath]; 
    [path moveToPoint:CGPointMake(Center.x, Center.y)]; 
    [path addLineToPoint:CGPointMake(Point.x,Point.y)]; 

    CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
    shapeLayer.path = [path CGPath]; 
    shapeLayer.strokeColor = [[UIColor whiteColor] CGColor]; 
    shapeLayer.lineWidth = 1.5; 
    shapeLayer.fillColor = [[UIColor clearColor] CGColor]; 

    [self.view.layer addSublayer:shapeLayer]; 

내가 다른 Point을 가지고있는 라인을 애니메이션 할 필요가 잠시 후,하지만 그대로 Center을 유지하지만, 어떻게해야할지 모르겠다. 내 접근 방식은 괜찮습니까? 그렇게 할 수있는 더 좋은 방법이 있습니까?

+0

가능한 중복 (http://stackoverflow.com/questions/15651717/how-to-animate-cashapelayer-path-and- [CAShapeLayer 경로와하고 fillColor 애니메이션을하는 방법] fillcolor) –

+0

경로의 그림에 애니메이션 효과를 적용하고 이미 그려진 부분을 애니메이션으로 만들지 않습니다 (달성하려는 부분). 감사합니다. :디 – Shamy

답변

2

그것을 해결 :

CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:@"path"]; 
    morph.duration = 1.0; 
    UIBezierPath *path5 = [UIBezierPath bezierPath]; 
    [path5 moveToPoint:CGPointMake(P22.x+5, P22.y+5)]; 
    [path5 addLineToPoint:CGPointMake(P21.x,P21.y)]; 
    morph.fromValue = (id) path.CGPath; 
    morph.toValue = (id) path5.CGPath; 

    [shapeLayer addAnimation:morph forKey:nil]; 

    //next line to update the shapeLayer's new path 
    shapeLayer.path = path5.CGPath; 
관련 문제