2012-03-28 22 views
0

Objective-Cプログラミングの新機能です。新しい行を描くと古い行が消える

私の問題は、touchesMovedで線を描くことです。

私のコードは次のようである:

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetShouldAntialias(context, YES); 

    CGContextSetLineWidth(context, 7.0f); 

    CGContextSetRGBStrokeColor(context, 0.7, 0.7, 0.7, 1.0); 

    CGContextMoveToPoint(context, self.touchedPoint2.x, self.touchedPoint2.y); 

    CGContextAddLineToPoint(context, self.touchedPoint.x, self.touchedPoint.y); 

    CGContextDrawPath(context,kCGPathFillStroke); 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.touchedPoint = [[touches anyObject] locationInView:self]; 

    [self setNeedsDisplay]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.touchedPoint2 = [[touches anyObject] locationInView:self]; 
} 

答えて

1

これが動作するようになっているかdrawRect:です。

すべてをオフスクリーンバッファー(例:CGImageまたはCGLayer)に描画し、次にdrawRect:を使用してバッファーを描画する必要があります。

他の可能性を列挙するquestionも参照してください。

関連する問題