2017-02-02 1 views
0

UIBezier Path를 원을 그리며 움직이면서 획 색상을 변경했습니다. 그것이 모든 방향으로 나아갈 때, 저는 그것이 반대 방향으로 계속 나아가고 싶습니다. 그러나, 나는, 앞으로 및 뒤로 경로를 애니메이트하는 방법?

[CATransaction begin]; 
    { 
     [CATransaction setAnimationDuration: 3.0];//Dynamic Duration 
     [CATransaction setCompletionBlock:^{ 
      [tutorialCircle removeFromSuperlayer]; 
      tutorialCircle.opacity = 0.0; 
      strokePart.opacity = 0.0; 
      [strokePart removeFromSuperlayer]; 
     }]; 

     const double portion = 1.0/((double)3); 

     for (NSUInteger i = 0; i < 3; i++) 
     { 
      strokePart = [[CAShapeLayer alloc] init]; 
      strokePart.fillColor = [[UIColor clearColor] CGColor]; 
      strokePart.frame = tutorialCircle.bounds; 
      strokePart.path = tutorialCircle.path; 
      strokePart.lineCap = tutorialCircle.lineCap; 
      strokePart.lineWidth = tutorialCircle.lineWidth; 

      if (i == 0) { 
       strokePart.strokeColor = [UIColor greenColor].CGColor; 
      } 

      else if (i == 1) { 
       strokePart.strokeColor = [UIColor orangeColor].CGColor; 
      } 

      else if (i == 2) { 
       strokePart.strokeColor = [UIColor redColor].CGColor; 
      } 
      strokePart.strokeStart = i * portion; 
      strokePart.strokeEnd = (i + 1) * portion; 

      [tutorialCircle addSublayer: strokePart]; 

      animation = [CAKeyframeAnimation animationWithKeyPath: @"strokeEnd"]; 
      NSArray* times = @[ @(0.0), // Note: This works because both the times and the stroke start/end are on scales of 0..1 
           @(strokePart.strokeStart), 
           @(strokePart.strokeEnd), 
           @(1.0) ]; 
      NSArray* values = @[ @(strokePart.strokeStart), 
           @(strokePart.strokeStart), 
           @(strokePart.strokeEnd), 
           @(strokePart.strokeEnd) ]; 

      animation.keyTimes = times; 
      animation.values = values; 
      animation.removedOnCompletion = YES; 
      animation.fillMode = kCAFillModeForwards; 
      [animation setDelegate:self]; 
      [strokePart addAnimation: animation forKey: @"whatever"]; 
     } 
    } 
    [CATransaction commit]; 

은 그래서 첫 번째 애니메이션 내 animationDidStop 위임 방법, 나는 뒤로 가서 두 번째 애니메이션을 호출 할 줄 알고 여기

는 앞으로 이동하게 코드 이것에 대한 애니메이션을 만들기 위해 뒤죽박죽이다.

답변

0

시도해 보셨습니까? 이 돌아 오면

animation.autoreverses = YES

+0

예는 거의 정확하게 내가 원하는하지만 서로 다른 색상을 깜박 않습니다 –

관련 문제