是否可以偏移UITouch点?我正在使用下面显示的触摸方法。我想通过一些数字来偏移触摸点,这样用户就可以看到触摸开始和绘制的位置。如果我试图在线条内绘画,我希望看到我的指尖上方,就像我们用钢笔和铅笔一样。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// add the first touch
UITouch *touch = [touches anyObject];
previousPoint = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
// init the bezier path
self.currentTool = [self toolWithCurrentSettings];
self.currentTool.lineWidth = self.lineWidth;
self.currentTool.lineColor = self.lineColor;
self.currentTool.lineAlpha = self.lineAlpha;
[self.currentTool setInitialPoint:currentPoint];
...
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// save all the touches in the path
UITouch *touch = [touches anyObject];
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
//currentPoint.y += 40;
CGRect bounds = [(DrawingPenTool*)self.currentTool addPathPreviousPoint:previousPoint2 withPreviousPoint:previousPoint1 withCurrentPoint:currentPoint];
CGRect drawBox = bounds;
drawBox.origin.x -= self.lineWidth * 2.0;
drawBox.origin.y -= self.lineWidth * 2.0;
drawBox.size.width += self.lineWidth * 4.0;
drawBox.size.height += self.lineWidth * 4.0;
[self setNeedsDisplayInRect:drawBox];
[self.currentTool moveFromPoint:previousPoint1 toPoint:currentPoint];
[self setNeedsDisplay];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event];
CGPoint point = [[touches anyObject] locationInView:self];
[self.currentTool setInitialPoint:point];
}
}
1条答案
按热度按时间qni6mghb1#
您可以使用UIEvent
predictedTouches
和UITouchestimatedProperties
来了解 * 下一次 * 触摸可能在哪里。通过这种方式,您可以保持在用户的“前面”进行绘制。这正是这个功能的作用。