ユーザーが画面に触れて指をドラッグすると、iPadに線が作成されます。問題は、(touchMoved:) ドラッグすることによってすべてのポイントで線が作成されることです。しかし、最終的には、多くではなく 1 つだけにする必要があります。新しい行を作成した後、最後の行を消去または削除するにはどうすればよいですか? これが私のコードです:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(ArrowDraw==YES){
NSLog(@"ArrowDrawing");
if ([[event allTouches]count]==1){
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:FullImageView];
UIGraphicsBeginImageContext(self.view.frame.size);
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), firstPoint.x, firstPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1 );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.tempDrawImage setAlpha:opacity];
UIGraphicsEndImageContext();
//firstPoint = currentPoint;
NSLog(@"TouchMoving x=%f y=%f",firstPoint.x,firstPoint.y);
}
UIGraphicsBeginImageContext(self.FullImageView.frame.size);
[self.FullImageView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
self.FullImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.tempDrawImage.hidden=YES;
}
}