Я хочу сохранить путь движения пальца на экране iPhone. На данный момент я просто читаю штрихи и добавляю CGPoints в NSMutableArray. когда я пытаюсь напечатать все cgpoint в этом массиве, как он пропускает промежуточные точки. Есть ли лучший способ этого? Можем ли мы хранить весь путь напрямую?Как сохранить путь движения пальца в объективе c?
Вот код, который я использую
- (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
Почему, по вашему мнению, отсутствуют промежуточные точки? Кроме того, вы хотите очистить массив 'myPoints' в' touchhesBegan: withEvent: '? –