1
我試着在ipad上創建一個簡單的手指繪畫應用程序。我能夠正確繪製一條路徑到屏幕,但我想要一個完全清除所有繪製路徑屏幕的選項。我目前的代碼清除了上下文,但是當我調用繪圖代碼塊時,所有路徑都會重新出現在屏幕上。如何清除CGContextRef?
- (void)drawRect:(CGRect)rect
{
//Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
if(clearContext == 0){
CGContextSetLineWidth(context, 6);
CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
CGContextAddPath(context, drawingPath);
CGContextStrokePath(context);
}
if(clearContext == 1){
//This is the code I currently have to clear the context, it is clearly wrong
//Just used as experimentation.
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextAddPath(context, drawingPath);
CGContextStrokePath(context);
clearContext = 0;
}
}
完美地工作...謝謝! – Michael