如何使用CoreAnimationanimation像钟倒计时一样的圆

我希望有一个倒计时的指标,就像一个圆从一个圆拱开始到一个整圆。

我已经尝试了几种方法,最终都是直接将拱门转成一个整圆,而不是顺时针方向。 演示图片如下所示:

演示时钟动画

任何想法? 不胜感激!

SetNeedsDisplay当你改变一个angular度,你可以做一些优化,只重绘受影响的区域。 把这样的东西放到你的视图的绘图函数中。 祝你好运

CGContextRef myContext = UIGraphicsGetCurrentContext(); CGPoint center = { self.bounds.size.width * 0.5f, self.bounds.size.height * 0.5f }; CGContextClearRect(myContext, rect); CGContextMoveToPoint(myContext, center.x, center.y); // start and end are in radians. CGContextAddArc(myContext, center.x, center.y, MIN(self.frame.size.width,self.frame.size.height)*0.5f, _startAngle, _endAngle, NO); CGContextAddLineToPoint(myContext, center.x, center.y); CGContextClip(myContext); CGContextSetFillColorWithColor(myContext,[UIColor redColor].CGColor); CGContextFillRect(myContext, self.bounds);