2

我正在使用UICircularProgressView并将其更改为我喜欢的。初始化很清楚,但无论如何我都会发布它:

UICircularProgressView *wheelProgress = [[UICircularProgressView alloc]initWithFrame:CGRectMake(someFrame)];

然后我正在设定正确的进度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];

但不知何故这不起作用..

有什么想法我需要在这里解决吗?

在此先感谢塞巴斯蒂安

4

1 回答 1

1

您正在使用的进度视图未设置为将进度作为动画属性。这样做非常复杂,我不确定它是否是您正在寻找的。

如果是,我认为您需要执行以下操作(我自己没有这样做,这只是基于我阅读过的文档和书籍):

  1. 重写视图以使用CALayers 而drawInContext不是drawRect
  2. progress图层上创建一个属性(使用@dynamic而不是@synthesize
  3. 覆盖actionForKey:图层子类并CABasicAnimation为键返回 a@"progress"

这方面的例子可以在一些 SO 问题/答案中找到:herehere应该让您开始或至少习惯可以使用的搜索词。看起来像是一个使用图层在饼图中绘制动画切片的好教程,这可能比从 UICircularProgressView 开始更接近您想要的。

或者,您可以使用 NSTimer 来实现这一点,它每 1/60 秒增加一次进度值,直到达到您想要的值。

于 2012-04-24T09:13:03.690 回答