Я использую SKShapeNodes для динамического рисования линий, обновляя свойство пути, когда пользователь касается экрана. Как только линия будет завершена, я хотел бы добавить новую перпендикулярную линию фиксированной длины к концу пути.
Я изучил CGAffineTransform, чтобы повернуть новую строку на основе конечной точки пути, но пока не повезло. Любые советы или понимание будут высоко оценены.
Некоторые из моих текущих кодов для справки выглядят так:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
//add a line to the new coordinates the user moved to
CGPathAddLineToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//create local copy of path
CGPathRef myPath_ = pathToDraw;
CGPoint myPoint = CGPathGetCurrentPoint(pathToDraw);
//create rectangle to append to end of line
CGRect newRect = CGRectMake(myPoint.x, myPoint.y, 25, 3);
CGPathRef newPath = CGPathCreateWithRect(newRect, NULL);
//add new line to the end of the path
CGPathAddPath(newPath, NULL, myPath_);
//set shape node path to drawn path
lineNode.path = myPath_;
}