Wie zu Animieren CoreGraphics Zeichnung der Form Mit CAKeyframeAnimation

Ich versuche zu animieren, die Zeichnung eines UIBeizerPath (in meinem Beispiel ein Dreieck) in eine UIView-Unterklasse. Aber, die gesamte Untersicht wird die Animation statt die Form.

Gibt es etwas, was ich bin fehlt mit der animation?

- (void)drawRect:(CGRect)rect {

   CAShapeLayer *drawLayer = [CAShapeLayer layer];

   drawLayer.frame           = CGRectMake(0, 0, 100, 100);
   drawLayer.strokeColor     = [UIColor greenColor].CGColor;
   drawLayer.lineWidth       = 4.0;

   [self.layer addSublayer:drawLayer];

   UIBezierPath *path = [UIBezierPath bezierPath];

  [path moveToPoint:CGPointMake(0,0)];
  [path addLineToPoint:CGPointMake(50,100)];
  [path addLineToPoint:CGPointMake(100,0)];
  [path closePath];

  CGPoint center = [self convertPoint:self.center fromView:nil];

  [path applyTransform:CGAffineTransformMakeTranslation(center.x, center.y)];

  [[UIColor redColor] set];

  [path fill];

  [[UIColor blueColor] setStroke];

  path.lineWidth = 3.0f;

  [path stroke];

  CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

  pathAnimation.duration        = 4.0f;
  pathAnimation.path            = path.CGPath;
  pathAnimation.calculationMode = kCAAnimationLinear;

  [drawLayer addAnimation:pathAnimation forKey:@"position"];
}
  • Genau erklären, was "animieren der Zeichnung eines UIBezierPath" bedeutet. Wollen Sie es zum zeichnen der einzelnen Segmente, eins nach dem anderen, oder was?
  • ja, ich möchte animieren der Zeichnung jeder Punkt, so wird das Dreieck zu sein schien, animierte
Schreibe einen Kommentar