Я хочу сохранить траекторию движения пальцев на экране iPhone.На данный момент я просто читаю прикосновения и добавляю CGPoints в NSMutableArray.когда я пытаюсь напечатать все точки cgpoint в этом массиве, как некоторые промежуточные точки.Есть ли лучший способ для этого?Можем ли мы сохранить весь путь напрямую?
Вот код, который я использую
- (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]];
}
}