我有一個組件,它有一個UIView子類和一個自定義的CAlayer。CALayer和UIView的差異圖
在UIView的存在是繪製CoreGraphics中的圓圈,這是代碼:
CGRect b = self.bounds;
int strokeSize = 2;
CGRect arcBounds = CGRectMake(b.origin.x+1, b.origin.y+1, b.size.width-2, b.size.height-2);
CGContextSaveGState(ctx); {
CGContextSetLineWidth(ctx, strokeSize);
CGContextSetStrokeColorWithColor(ctx, [UIColor lightGrayColor].CGColor);
CGContextStrokeEllipseInRect(ctx, arcBounds);
} CGContextRestoreGState(ctx);
當我繪製了UIView內drawRect方法是圓它完美的作品和繪製圓光滑,看起來不錯。
問題出現在我畫另一個圓時,但第二個畫在CALayer中,實際上是在我的自定義CALayer的drawInContext方法中。使用相同的代碼,圓圈看起來不太好,並且在邊界上有一些「像素化」。
任何可能發生的線索的線索?提前致謝。