Sto provando ad animare il disegno di un UIBeizerPath (nel mio esempio un triangolo) in una sottoclasse UIView. Tuttavia, l'intera sottoview si sta animando invece della forma.Come animare il disegno di forma di CoreGraphics usando CAKeyframeAnimation
C'è qualcosa che mi manca con l'animazione?
- (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"];
}
spiegare esattamente ciò che "animano il disegno di un UIBezierPath" si intende. Vuoi disegnare i singoli segmenti, uno dopo l'altro, o cosa? –
@kurt yes Mi piacerebbe animare il disegno di ogni punto in modo che il triangolo sembrasse essere animato –