在iOS中创buildanimation进度条

我正在尝试为iPad应用程序制作自定义的animation条形图(即,条形高度在激活时会增加到设定的水平)。 我对iOS开发很陌生,我只想获得关于如何处理这个任务的反馈。

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

如果你只是想要一个实心的酒吧,你可以创build一个你需要的大小和位置的UIView,设置它的背景颜色,并将其添加到您的视图。 这是不错的代码,使用UIView绘制实心矩形并不丢脸。 :]

对于更复杂的graphics,您可能需要创buildUIView的自定义子类并覆盖其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); } 

或者任何其他CGContexttypes的绘图(例如饼图,折线图等)。

要通过添加具有背景色的UIView创build一个条形图,请在animation启动时粘贴以下内容:

 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); } 

idk关于这个链接,但你可以从这里生成它们http://preloaders.net/ ,应该给你一个很好的基础,使自己的