我想绘制一条线(在iphone上),这样我就可以查看每个正在绘制的像素。如何使用对象绘制一个像素逐像素C
我目前使用定时器调用drawRect方法。
以下是我在哪里使用绘制从数组的值的波的代码:
static int i=0;
int x = 10;
int y = 0;
int x2;
int y2;
- (void)drawRect:(CGRect)rect
{
// Drawing code.
CGContextRef c = UIGraphicsGetCurrentContext();
CGFloat black[4] = {0.0f,0.0f,0.0f,1.0f};
CGContextSetStrokeColor(c, black);
CGContextBeginPath(c);
NSLog(@"fired...");
int ecg[358] = {36, 37, 37, 36, 34, 33, 33, .... ,36}; //Assume the data is there
CGContextMoveToPoint(c, x, y);
x2 = i;
y2 = ecg[i];
CGContextAddLineToPoint(c, x2, y2);
x = x2;
y = y2;
CGContextStrokePath(c);
[self setNeedsDisplay];
i++;
}
- (void) awakeFromNib
{
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(drawRect:) userInfo:nil repeats:YES];
}
我只能看到在一次一行被拉伸时的drawRect被调用。但我没有看到整个图像。我想不出一种不同的方法来看到屏幕上正在绘制的波浪。
此外,initWithFrame方法永远不会被调用,所以不得不与awakeFromNib一起去声明计时器,如果我错了,请纠正我。
任何指向动画线条图的指针都会有所帮助。
谢谢
每次调用drawRect时,都会清除上下文。所以你必须重新绘制一切到你想要的点。 – DarkDust 2011-04-01 14:03:31
@DarkDust:是的,我明白了,你能为此提出一种不同的方法吗? – R3D3vil 2011-04-01 14:22:51