皆さん、
いくつかのダイヤルとスライダーをコーディングしている間 (たとえば、回転できる大きな音量ボタンなど)、標準の CGContextAddArc() が次のように使用されていることがわかりました。
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();
CGContextSetLineWidth(ctx, radius * (KE-KR)+8);
CGContextSetStrokeColorWithColor(ctx,self.foregroundColor.CGColor);
.... more some colour/width/etc settings
...
CGContextAddArc(ctx, dx,dy,radius, 0, 2*M_PI, 0);
信じられないほど遅くなります。
iPad の場合 - いくつかの塗りつぶし/ストロークの円があり、ドラッグ中のクリーンな [self setNeedsDisplay] の更新は 1 秒あたり 10 回未満です。手描きの円 (下図) を使った非常に簡単なハックは、桁違いに高速でした。エミュレーターも同様です。
どうしてこれなの。通常の塗りつぶしとさまざまなグラデーション塗りつぶしの両方に当てはまるようです。私は何を間違っていますか?
Dw。
// Stupid replacement for CGContectAddArc() which seems to be very slow.
//
void CGContextAddCirlce(CGContextRef ctx, float ox, float oy, float radius)
{
double len = 2 * M_PI * radius;
double step = 1.8 / len; // over the top :)
// translating/scaling would more efficient, etc..
//
float x = ox + radius;
float y = oy;
// stupid hack - should just do a quadrant and mirror twice.
//
CGContextMoveToPoint(ctx,x,y);
for(double a = step; a < 2.0 * M_PI -step; a += step) {
x = ox + radius * cos(a);
y = oy + radius * sin(a);
CGContextAddLineToPoint(ctx, x, y);
};
CGContextClosePath(ctx);
};