iPhone の CALayer 描画で奇妙な問題が発生しています。「泡」を表す一連のサブレイヤーを追加するルートレイヤーがあります。最終結果は次のようになります。
http://www.expensivedna.com/IMG_0018.PNG http://www.expensivedna.com/IMG_0018.PNG
問題は、レイヤーをアンチエイリアスにできないように見えることです (バブルのギザギザに注意してください)。バブル CALayer の drawInContext を上書きする私のコードは次のとおりです。
- (void)drawInContext:(CGContextRef)theContext{
CGContextSetAllowsAntialiasing(theContext, true);
CGContextSetShouldAntialias(theContext, true);
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1.0, 1.0, 1.0, 0.5, // Start color
1.0, 1.0, 1.0, 0.0 }; // End color
CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef glossGradient =
CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGPoint topCenter = CGPointMake(25, 20);
CGPoint midCenter = CGPointMake(25, 25);
CGContextDrawRadialGradient(theContext, glossGradient, midCenter, 20, topCenter, 10, kCGGradientDrawsAfterEndLocation);
}
ここで非常に奇妙なのは、描画コードをわずかに変更して、次のように通常の赤い円のみを描画することです。
- (void)drawInContext:(CGContextRef)theContext{
CGContextSetAllowsAntialiasing(theContext, true);
CGContextSetShouldAntialias(theContext, true);
CGContextSetFillColorWithColor(theContext, [UIColor redColor].CGColor);
CGContextFillEllipseInRect(theContext, CGRectMake(0, 0, 40,40));
}
すべてがアンチエイリアスに問題ないようです:
http://www.expensivedna.com/IMG_0017.PNG http://www.expensivedna.com/IMG_0017.PNG
この一見奇妙な動作を理解できないようです。アンチエイリアシング グラデーションと通常の円の違いがわかりませんか?
みんなありがとう。