【发布时间】:2011-03-10 05:54:27
【问题描述】:
我要做的是创建一个自定义进度条,用石英绘图,我做的是以下,
- (void)drawRect:(CGRect)rect {
// Drawing code.
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect currentBounds = self.bounds;
CGContextSetLineWidth(context, 20.0f);
CGContextSetStrokeColorWithColor(context, [ProgressBarView redColor]);
CGContextBeginPath(context);
CGContextMoveToPoint(context, CGRectGetMinX(currentBounds), CGRectGetMidY(currentBounds));
CGContextAddLineToPoint(context, CGRectGetMaxX(currentBounds) * time, CGRectGetMidY(currentBounds));
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathStroke);
}
在 CGContextAddLineToPoint 中,我将 maxX 乘以时间,这是每秒使用此函数计算的时间。
- (void)pushTime {
if (time >= 1.0) {
time = 0.0;
} else {
time = time += 0.1;
}
[self setNeedsDisplay];
}
第一次效果很好,但是进度条永远不会回到起点,我已经尝试将起始值更改为 0 以外的值,以便石英可以毫无问题地创建路径,但这并没有去做吧。
无论如何,谢谢你的帮助。
【问题讨论】:
-
什么是“时间”?一个INT?一个浮子?一个NSNumber ...?你在哪里叫pushTime?通过 NSTimer?
标签: iphone quartz-graphics drawrect