プラス記号の形をしたクリッピングパスを作成しようとしています。これにより、同じコンテキストに描画する後続のパスでこの部分が削除されます。2つの長方形のパスを重ねて使用してクリッピングパスを作成します。
これは、後で円を描くときに最終的な描画がどのようになるかを示しています。
xXX | | XXx
XXXX | | XXXX
XXXXX | | XXXXX
———&nbsp; ——— <br /> ———&nbsp; ——— <br /> XXXXX | | XXXXX
XXXX | | XXXX
xXX | | XXx
ただし、実際には次のようになります。
xXX | | XXx
XXXX | | XXXX
XXXXX | | XXXXX
———&nbsp; XX ——— <br /> ———&nbsp; XX ——— <br /> XXXXX | | XXXXX
XXXX | | XXXX
xXX | | XXx
この動作を正しく読んだ場合、2つの長方形のパスの交点はクリッピングマスクの一部を形成していません。
この場合、appendPathは2つの長方形のパスから単一の統合パスを作成しないようです-これについては何もできないと思います。さらに、CoreGraphicsにはパスユニオンなどに関連する機能がないようです。
誰かが私に何ができるか考えていますか?関連するコードスニペットを含めました。
クリッピングマスクに他の重複するパスを追加したいので、1つのパスを使用してプラス記号を描画することは解決策ではありません。
CGContextSaveGState(context);
// create clipping path
UIBezierPath *clippingPath = [UIBezierPath bezierPath];
clippingPath = [UIBezierPath bezierPathWithRect:CGRectMake(centrePoint.x - 2.0f, 0.0f, 4.0f, self.sizeY)];
[clippingPath appendPath:[UIBezierPath bezierPathWithRect:CGRectMake(0.0f, centrePoint.y - 2.0f, self.sizeX, 4.0f)]];
// use the clipping path to create a hole in the context
CGContextAddPath(context, clippingPath.CGPath);
CGRect boundingRect = CGContextGetClipBoundingBox(context);
CGContextAddRect(context, boundingRect);
CGContextEOClip(context);
// draw the icon shape (clipped portion is removed)
iconBezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(self.sizeX / 3.0f, self.sizeY / 2.25f, self.sizeX / 3.0f, self.sizeX / 3.0f)];
[highlightColor setFill];
[iconBezierPath fill];
CGContextRestoreGState(context);