我正在试图制作条形图,这是我到目前为止所做的:
CGContextBeginPath(context);
for (int i=0; i<[data count]; ++i) {
CGContextMoveToPoint(context,kOffsetX+i*kStepX, kGraphHeight-kOffsetY);
CGContextAddLineToPoint(context, kOffsetX+i*kStepX, (kGraphHeight-kOffsetY)-(kGraphHeight-kOffsetY-kGraphTop)*([[data objectAtIndex:i]floatValue]/maxDataPoint));
}
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.path=CGContextCopyPath(context);
[self.layer addSublayer:pathLayer];
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 0.5;
pathAnimation.fromValue = @0;
pathAnimation.toValue = @1;
[pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
由于路径是从左到右的条形,&#34; strokeEnd&#34; -Animation从左到右动画,但我想要一个从下到上的动画,所以条形图上升。我是否需要更改动画的键或其他方式来绘制路径?
谢谢!