ios - 删除 CGContextAddPath 之后的路径

标签 ios cocoa cgcontext

我想知道在使用 CGContextAddPath 添加 CGPath 后是否有办法从上下文中删除 CGPath,以便之后我的绘图命令不再局限于路径尺寸。

最佳答案

您应该使用CGContextBeginPath(...)从指定上下文中删除先前添加的路径。

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.

类似于下面:

CGContextRef context = UIGraphicsGetCurrentContext();

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

CGContextBeginPath(context);

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

关于ios - 删除 CGContextAddPath 之后的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11366689/

相关文章:

cocoa - NSManagedObject 作为 NSDictionary 键?

macos - Nib 的自定义类无法连接到类

iphone - CGLayerCreateWithContext CGContext 泄漏

ios - UIScrollView 缩放仅用 2 个手指

iphone - iOS : Core Text - loosing context when drawing image inside a block

iPhone:如何允许在自定义单元格的表格 View 中进行多项选择?

ios - 如何获取已通过 snapkit 设置的 UIView 的框架

javascript - 使用自定义方案打开应用程序 - 防止 "open in <appname>"警告?

ios - FB 应用程序和 FB Messenger 之间的连接

cocoa - NSCollectionView 可以自动调整其 subview 的宽度以显示一列