[英]Animating UICircularProgressView
我正在使用UICircularProgressView并将其更改为我喜欢的。 初始化很清楚,但我还是会发布它:
UICircularProgressView *wheelProgress = [[UICircularProgressView alloc]initWithFrame:CGRectMake(someFrame)];
然后我将正确的进度CGFloat between 0-1
设置为CGFloat between 0-1
CGFloat progress = .3; // example
[self.wheelProgress setProgress:progress];
这工作得很好,并且看起来不错,但是我真的想以某种方式对其进行动画处理。 到目前为止,我还没有制作动画,所以我的第一种方法是
for(tempProgress =! progress){
incrementing tempProgress
setting tempProgres to progressView
}
这当然很丑陋,并且阻止了其他所有事情。
我想实现的是从0到最终值的线性动画。
我看过: 动画教程
并想到了这样的事情:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration: 1];
wheelProgress.progress = (progress) ? progress : 0.0;
[UIView commitAnimations];
但这不起作用
任何想法我需要在这里解决?
预先感谢塞巴斯蒂安
您正在使用的进度视图未设置为将进度作为可设置动画的属性。 这样做非常复杂,我不确定这是否是您要寻找的。
如果是这样,我认为您需要执行以下操作(我自己还没有做过,这只是基于我已阅读的文档和书籍):
CALayer
和drawInContext
而不是drawRect
progress
成为图层上的属性(使用@dynamic
而不是@synthesize
actionForKey:
并为键@"progress"
返回CABasicAnimation
可以在一些SO问题中找到此类示例: 在这里和这里应该可以帮助您入门,或者至少习惯了可以使用的搜索词。 这看起来像是一个很好的教程,用于使用图层在饼图中绘制动画切片,与从UICircularProgressView开始相比,这可能更接近您想要的内容。
或者,您可以改为使用NSTimer来实现此目的,该方法每隔1/60秒增加一次进度值,直到达到所需值为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.