在iOS中创建动画进度条

时间:2011-09-29 04:07:22

标签: ios progress-bar

我正在尝试为iPad应用程序制作自定义动画条形图(即,条形高度增加到激活时设置级别)。我对iOS开发很陌生,我只想获得有关如何处理此任务的反馈。

我正试着在this条目中回答问题,我想知道从这一点开始是否正确。

2 个答案:

答案 0 :(得分:3)

如果您只想要一个实心条,您可以创建所需大小和位置的UIView,设置其背景颜色,并将其添加到视图中。这是一个不错的编码,使用UIView绘制实体矩形并不羞耻。 :

对于更复杂的图形,您可能希望创建UIView的自定义子类并覆盖其drawRect消息以执行一些自定义绘制。例如:

- (void)drawRect:(CGRect)rect
{
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextSetLineWidth(context, 4.0);
  CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0, 1.0); // opaque yellow
  CGContextMoveToPoint(context, x1, y1); // for suitable definition of x1,y1, etc
  CGContextAddLineToPoint(context, x2, y2);
  CGContextStrokePath(context);
}

或您可能想要做的任何其他CGContext *绘图(例如饼图,折线图等)。

要通过添加带背景颜色的UIView来动画您创建的栏,请在动画开始时粘贴以下内容:

timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
self.startTime = [NSDate date];

然后添加以下消息(注意:栏会向上增长)。

- (void) onTimer:(NSTimer*)firedTimer
{
  float time = [self.startTime timeIntervalSinceNow] * -1;
  if (time>kMaxTime)
  {
    [timer invalidate];
    timer = nil;
    time = kMaxTime;
  }
  int size = time * kPixelsPerSecond;
  myBar.frame = CGRectMake(x, y - size, width, size);
}

答案 1 :(得分:0)

关于该链接的idk,但你可以从这里http://preloaders.net/生成它们,这些应该为你提供一个很好的基础来制作你自己的链接

相关问题