如何清除EOFill / Fill?

时间:2011-11-02 19:08:07

标签: iphone objective-c cocoa ipad cgcontext

我知道CGContextClearRect可以让你清楚drawRect类中的所有内容。 如何选择一个CGContextRef并清除它? 对于我的情况,我的代码是:

//Put clearing syntax here
if(dp.gPoints == nil || dp.gPoints->size() < 1)
    return;
CGContextBeginPath(g);
vector<CGPoint>::iterator k = dp.gPoints->begin();
CGContextMoveToPoint(g, (*k).x, (*k).y);
++k;
while(k != dp.gPoints->end()){
    CGContextAddLineToPoint(g, (*k).x, (*k).y);
    ++k;
}
vector<CGPoint>::reverse_iterator L = dp.dPoints->rbegin();
while(L != dp.doodlePoints->rend()){
    CGContextAddLineToPoint(g, (*L).x, (*L).y);
    ++L;
}
//CGContextAddLineToPoint(g, (*k).x, (*k).y);
CGContextSetFillColor(g, CGColorGetComponents([[UIColor greenColor] CGColor]));
CGContextEOFillPath(g);

1 个答案:

答案 0 :(得分:1)

替换这两行:

CGContextSetFillColor(g, CGColorGetComponents([[UIColor greenColor] CGColor]));
CGContextEOFillPath(g);

这些行:

CGContextSaveGState(g);
CGContextEOClip(g);
CGContextClearRect(g, rect);
CGContextRestoreGState(g);

假设rect是传递给drawRect:方法的参数。