1

iPadで簡単なフィンガーペインティングアプリケーションを作成して実験しています。画面へのパスを正しく描画できますが、描画されたすべてのパスを画面から完全にクリアするオプションが必要です。私が現在持っているコードはコンテキストをクリアしますが、描画コード ブロックを呼び出すと、すべてのパスが画面に再表示されます。

- (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;

     }

}
4

2 に答える 2

4

drawingPath が CGPath であると仮定しています... CGPath をクリアしていますか? それがあなたの問題の原因かもしれません

パスをクリアするアクションで、次のようにします。

CGPathRelease(drawingPath);
drawingPath = CGPathCreateMutable();
[self setNeedsDisplay];

そして、通常行う通常の描画を行います。パスが空の場合、何も描画されません

于 2012-08-28T18:04:49.480 に答える
0

すべての CGContextRef 図面をクリア:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds); //self.bounds = your drawing base frame
[self setNeedsDisplay];
于 2020-07-19T21:14:20.073 に答える