iPhoneの画面に指の動きのパスを保存したい。現在、NSMutableArrayに触れてCGPointを追加するだけです。その配列内のすべてのcgpointを何点か途中で見つけられないように印刷しようとします。これには良い方法がありますか?パス全体を直接保存できますか?ここで指の動きのパスを目的のCにどのように保存できますか?
は、私はあなたがiOSのはあなたを与えて喜んですべてのポイントを記録している
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
fingerSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self.view];
[self.myPoints addObject:[NSValue valueWithCGPoint:lastPoint]];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
fingerSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
[slateImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth);
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0,0,0, 1.0);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), self.drawcolor.CGColor);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
slateImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
[myPoints addObject:[NSValue valueWithCGPoint:lastPoint]];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(!fingerSwiped)
{
UIGraphicsBeginImageContext(self.view.frame.size);
[slateImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth);
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0,0,0, 1.0);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), self.drawcolor.CGColor);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
slateImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[myPoints addObject:[NSValue valueWithCGPoint:lastPoint]];
}
}
ポイントを配列に追加するコードを共有できます – dbrajkovic
これまで忘れてしまったことがあります。 – slonkar
なぜあなたはそれが中間点を欠いていると思いますか?また、 'touchesBegan:withEvent:'の 'myPoints'配列をクリアしますか? –