我有一个小的运行速度问题。在加载时,我生成了一个至少包含 1000 个点的 CGMutablePath。我想在屏幕上滚动这条路径,所以我使用这种代码:
-(void) drawRect:(CGRect)rect {
/*
Here, I have a timer calling drawRect 60 times per second.
There's also code for the scale and currentTime, based on
an MP3 playback (AVAudioPlayer);
*/
CGContextRef ref = UIGraphicsGetCurrentContext();
CGContextClearRect(ref, [self frame]);
CGContextSaveGState(ref);
CGContextTranslateCTM(ref, s.width/2+currentTime, 1);
CGContextScaleCTM(ref, scale, 1);
CGContextAddPath(ref, myGraphPath);
CGContextSetRGBFillColor(ref, .1, .1, .1, .8);
CGContextFillPath(ref);
CGContextRestoreGState(ref);
}
问题是它有点慢,不是很慢,但是因为我需要添加更多的图形代码......我想知道设备是否正在绘制整个路径(一旦应用了比例,路径就是大约 10.000 像素宽),或者只是屏幕上可见的部分?我能做些什么来优化这个?