Olshansky
Olshansky

Reputation: 6404

Remove Path after CGContextAddPath

I was wondering if there is a way to remove a CGPath from my context after I added it using the CGContextAddPath such that my drawing commands are no longer limited to the path dimensions afterwards.

Upvotes: 1

Views: 1423

Answers (2)

Matt Robinson
Matt Robinson

Reputation: 897

You should use CGContextBeginPath(...) to remove the previously added path from the specified context.

Discussion for the method from Apple's documentation:

A graphics context can have only a single path in use at any time. If the specified context already contains a current path when you call this function, Quartz discards the old path and any data associated with it.

The current path is not part of the graphics state. Consequently, saving and restoring the graphics state has no effect on the current path.

Similar to below:

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextAddPath(context, ellipsePath);
CGContextDrawPath(context, kCGPathFill);

CGContextBeginPath(context);

CGContextAddPath(context, strokePath);
CGContextDrawPath(context, kCGPathStroke);

Upvotes: 3

Mundi
Mundi

Reputation: 80273

There is no way to remove a path once it is in the context. Just redraw without that particular path.

Upvotes: 0

Related Questions