iphone - 使用 CABasicAnimation 动画圆的 endAngle
<p><p>我有一些带有 drawrect 代码的 UIView 用于绘制饼图:</p>
<pre><code> - (void)drawRect:(CGRect)rect
{
CGRect parentViewBounds = self.bounds;
CGFloat x = CGRectGetWidth(parentViewBounds)/2;
CGFloat y = CGRectGetHeight(parentViewBounds)/2;
// Get the graphics context and clear it
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
// define line width
CGContextSetLineWidth(ctx, 4.0);
CGContextSetFillColor(ctx, CGColorGetComponents( ));
CGContextMoveToPoint(ctx, x, y);
CGContextAddArc(ctx, x, y, 100,radians(270), radians(270), 0); // 27
CGContextClosePath(ctx);
CGContextFillPath(ctx);
}
</code></pre>
<p>但是当我尝试在绘制后为“endAngle”属性设置动画时,它不起作用:</p>
<pre><code>CABasicAnimation *theAnimation;
theAnimation=;
theAnimation.duration=1;
theAnimation.repeatCount=1;
theAnimation.autoreverses=NO;
theAnimation.fromValue=;
theAnimation.toValue=;
[ addAnimation:theAnimation forKey:@"animateLayer"];
</code></pre>
<p>我在哪里犯了错误? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果你想制作动画,那么你应该考虑使用 Core Animation 进行绘图。它使动画更简单。</p>
<p>看看<a href="http://blog.pixelingene.com/2012/02/animating-pie-slices-using-a-custom-calayer/" rel="noreferrer noopener nofollow">this great tutorial on making a custom animatable pie chart with Core Animation</a> .我相信你可以修改它以获得你想要的。 </p>
<p>如果您觉得这很复杂,那么您可以查看 <a href="https://stackoverflow.com/a/10651797/608157" rel="noreferrer noopener nofollow">my answer</a>至<a href="https://stackoverflow.com/q/3729690/608157" rel="noreferrer noopener nofollow">"Draw part of a circle"</a>它通过画一个非常宽的圆圈来绘制饼图形状。</p></p>
<p style="font-size: 20px;">关于iphone - 使用 CABasicAnimation 动画圆的 endAngle,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/12787582/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/12787582/
</a>
</p>
页:
[1]