0

このコードでは、CGContextRef を使用して UIView に次の画像を作成します。

http://imgur.com/gPtBAEO

CGMutablePathRef arc = CGPathCreateMutable();
CGFloat lineWidth = 16.0;
CGContextRef cont = UIGraphicsGetCurrentContext();
CGContextFlush(cont);
CGContextSetStrokeColorWithColor(cont, [UIColor grayColor].CGColor);
CGContextSetFillColorWithColor(cont, [UIColor clearColor].CGColor);

for (int i = 0; i < 16; i++) {
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-8.0f), DEG_TO_RAD(_deg1*i), DEG_TO_RAD(_deg1*(i+1)), NO);
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10);
    CGContextAddPath(cont, strokedArc);
}

for (int i = 0; i < 8; i++) {
    arc = CGPathCreateMutable();
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-24.0f), DEG_TO_RAD(_deg2*i), DEG_TO_RAD(_deg2*(i+1)), NO);
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10);
    CGContextAddPath(cont, strokedArc);
}

for (int i = 0; i < 4; i++) {
    arc = CGPathCreateMutable();
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-40.0f), DEG_TO_RAD(_deg3*i), DEG_TO_RAD(_deg3*(i+1)), NO);
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10);
    CGContextAddPath(cont, strokedArc);
}

for (int i = 0; i < 2; i++) {
    arc = CGPathCreateMutable();
    CGPathAddArc(arc, NULL, cenPoint.x, cenPoint.y, halfWidthInc(-56.0f), DEG_TO_RAD(_deg4*i), DEG_TO_RAD(_deg4*(i+1)), NO);
    CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, 10);
    CGContextAddPath(cont, strokedArc);
}


CGContextDrawPath(cont, kCGPathFillStroke);

でもCATransform3Dで変身したい。そのためには、このコンテキストを UIView のサブレイヤーに描画する必要があります (UIView にさらにサブレイヤーを描画したいため)。この CGContextRef パスを UIView の別のサブレイヤーに描画するにはどうすればよいですか?

4

1 に答える 1

0

次の構築で修正します。

CGPathRef *board = CGContextCopyPath(cont);

_indi1 = [CAShapeLayer layer];
_indi1.frame = self.layer.bounds;
_indi1.bounds = CGRectInset(pathCont, 0, 0);
_indi1.geometryFlipped = YES;
_indi1.path = board;
_indi1.strokeColor = [[UIColor colorWithRed:125.0f/255.0f green:251.0f/255.0f blue:181.0f/255.0f alpha:1] CGColor];
_indi1.fillColor = nil;
_indi1.lineWidth = 1.0f;
_indi1.fillRule = kCAFillRuleEvenOdd;
_indi1.lineJoin = kCALineJoinRound;

[self.layer insertSublayer:_indi1 atIndex:0];

_indi1- CAShapeLayer 型を持つスーパークラスのプロパティ。それは機能しますが、結果はスムージングなしで見えます(生のピクセル化あり)。このような:ここに画像の説明を入力

どうすればそれを修正して画像をより滑らかにすることができますか?

PS: CGContext を CAShapeLayer に変換しようとすると、この問題がポップアップします。最初の例では、CGContext で作成すると、この問題は発生しませんでした。(トップポストの最初の例で見ることができます)

于 2016-04-22T09:24:20.443 に答える