我需要在视图上绘制几百条线和圆,并通过计时器函数使它们不断移动,其中我调用[myView setNeedsDisplay]来更新视图。
我从UIView子类(myView)中实现drawRect函数来执行以下操作...
-(void) drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat red[4] = { 1, 0, 0, 1};
CGContextSetLineWidth(context, 1);
CGContextSetShouldAntialias(context, NO);
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetStrokeColor(context, red);
// rects is an array of CGRect of size ~200
for (int i = 0; i < N; i++) {
CGContextAddEllipseInRect(context, rects[i]);
}
// points is an array of CGPoint of size ~100
CGContextAddLines(context, points, N);
CGContextStrokePath(context, color);
}
但是这个速度非常慢。我是否遗漏了什么? 完成一次绘制需要近1秒钟。