【问题标题】:Remove Path after CGContextAddPath删除 CGContextAddPath 之后的路径
【发布时间】:2012-07-06 17:08:01
【问题描述】:

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

【问题讨论】:

    标签: ios cocoa cgcontext


    【解决方案1】:

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

    来自Apple's documentation的方法讨论:

    一个图形上下文在任何时候都只能有一个使用的路径。如果调用此函数时指定的上下文已经包含当前路径,Quartz 会丢弃旧路径以及与之关联的任何数据。

    当前路径不是图形状态的一部分。因此,保存和恢复图形状态对当前路径没有影响。

    类似于下面:

    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextAddPath(context, ellipsePath);
    CGContextDrawPath(context, kCGPathFill);
    
    CGContextBeginPath(context);
    
    CGContextAddPath(context, strokePath);
    CGContextDrawPath(context, kCGPathStroke);
    

    【讨论】:

      【解决方案2】:

      一旦路径位于上下文中,就无法删除它。只是重绘没有那个特定的路径。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-27
        • 1970-01-01
        • 2021-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-21
        • 1970-01-01
        相关资源
        最近更新 更多