我需要在我的视图上绘制几百行和圆圈,并且他们继续通过计时器功能,我调用[myView setNeedsDisplay]来更新视图.
@H_502_19@解决方法@H_301_20@
我从UIView子类(myView)并实现drawRect函数来执行以下操作…
-(void) drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGFloat red[4] = { 1,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秒钟